Grep weird issue

Help
2008-05-07
2013-04-24
  • Paul Massey
    Paul Massey
    2008-05-07

    grep seems to take a file that is terminated by a CRLF and just makes it a LF.  My input file and the header file I create both have CRLF.  But the output file of my grep command is just a LF.  Anyone know why it does this.  Makes no sense to me.

    Code I am using:

    head -q -n1 input.txt > header.txt
    grep -v -f header.txt input.txt >> newfile.txt

     
    • Paul Massey
      Paul Massey
      2008-05-07

      Well I tried piping the grep output to sed to see if I could put the Carriage Return back in.
      I tried two different ways based on what I read on this website.
      http://sed.sourceforge.net/sed1line.txt
      Neither of them worked.

      head -q -n1 input.txt > header.txt
      grep -v -f header.txt input.txt | sed "s/$//" >> newfile.txt

      and

      head -q -n1 input.txt > header.txt
      grep -v -f header.txt input.txt | sed -n p >> newfile.txt

      I suppose I could just unix2dos the file but that doesn't seem to explain why grep does what it does.

       
    • Paul Massey
      Paul Massey
      2008-05-07

      I piped it to gawk 1 and it changed the line back to a CRLF.