2

I am trying to delete the string '\r\n' from a file.

Using sed:

cat foo | sed -e 's/\015\012//'

does not seem to work.

tr -d '\015' 

will delete a single character but I want to remove the string \015\012. Any suggestions?

savanto
  • 4,470
  • 23
  • 40
Dave
  • 577
  • 6
  • 25
  • Do you have `\r\n` like return\newline, or do you have the character `\r\n`. Give example text before and after. – Jotne Jun 05 '14 at 06:27
  • you want to put a full text fill from Windows/Dos format to 1 line ? or convert to a unix text file (leaving newline) ? – NeronLeVelu Jun 05 '14 at 06:57

2 Answers2

2

If I can offer a perl solution:

$ printf "a\nb\r\nc\nd\r\ne\n" | perl -0777 -pe 's/\r\n//g' | od -c
0000000   a  \n   b   c  \n   d   e  \n
0000010

The -0777 option causes the entire file to be slurped in as a single string.

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
1

What about:

sed ':a;N;$!ba;s/\r\|\n//g'

This is to remove any \r and \n characters. If you want the sequence \r\n, then use this:

sed ':a;N;$!ba;s/\r\n//g'

tuned from: https://stackoverflow.com/a/1252191/520567

Community
  • 1
  • 1
akostadinov
  • 17,364
  • 6
  • 77
  • 85