perl -e '$lc=0;while (<>) {$l=$_;chomp($l);$l=~s/^\s*//g;$l=~s/\s+/ /g;@ch=split(/ /,$l);if($lc++==0){print "\\begin{table}\n\\begin{tabular}{";foreach(@ch){print"l";}print"}\n";}$hc=0;foreach(@ch){if($hc++>0){print " & ";}print $_;}print " \\\\\n";}print "\\end{tabular}\n\\caption{\\label{tab:table-tag}Caption goes here!}\n\\end{table}\n";' < DATAFILE The datafile should contain one line of column headers, separated by spaces, followed by the data line by line, also separated by spaces: Input: col1 col2 col3 col4 col5 col6 0.0008 0.0144 0.4834 0.0980 0.1601 0.1403 278.3019 271.7593 272.2953 278.2213 272.6846 265.9941 0.1543 0.1533 0.5652 0.2473 0.3666 0.6602 0.1487 0.1368 0.5711 0.2391 0.3378 0.5920 0.1919 0.1798 0.5436 0.2686 0.3303 0.5166 Output: \begin{table} \begin{tabular}{llllll} col1 & col2 & col3 & col4 & col5 & col6 \\ 0.0008 & 0.0144 & 0.4834 & 0.0980 & 0.1601 & 0.1403 \\ 278.3019 & 271.7593 & 272.2953 & 278.2213 & 272.6846 & 265.9941 \\ 0.1543 & 0.1533 & 0.5652 & 0.2473 & 0.3666 & 0.6602 \\ 0.1487 & 0.1368 & 0.5711 & 0.2391 & 0.3378 & 0.5920 \\ 0.1919 & 0.1798 & 0.5436 & 0.2686 & 0.3303 & 0.5166 \\ \end{tabular} \caption{\label{tab:table-tag}Caption goes here!} \end{table}