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?
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?
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.
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