PROBLEM: Convert a csv file to LaTex. $ cat Data.csv %Rabbit Weight Tubby,10 Padma,9 Lakshmi, 6 Sarswati, 5 #Note that there is at least one blank line #Solution: % delete blank line(s) /^ *$/d % do not process comments lines /^ *%/d! % convert "," to "&" /s/,/\&/ % end each line with \cr /s/$/ \\\\cr/ $ sed '/^ *$/d;/^ *%/!{s/,/\&/;s/$/ \\\\cr/;}' Data.csv