Tuesday, January 15, 2008

cat a file line by line doesn’t work

When you wan’t to compute a file line by line in Bash (or other shell’s ?) with eg. with this command:

for L in $(cat lines.txt); do
   grep “$L” second-file.txt;
done

or

cat lines.txt | while read L; do
   grep “$L” second-file.txt
done

it does ONLY work if you use the UNIX line separator (\n). If you access a file, which was created on a windows system, such commands will not return the expected result. You have to convert the input file first. Do that with the little tool called “dos2unix”.

Posted by schmidi2 in 16:23:44
Comments

Leave a Reply