Very simply I have a file that has \r\n at every line break.
aaaa\r\nbbbb\r\ncccc
I would like to remove the \r character while leaving the \n in place.
I could do this easily in python but it seems to be more elegant with a simple sed command. Is this possible? What expression would do the trick? I can't seem to find any such solution online.
Thank you
The \r issue suggests you have edited the script file on a Windows machine. Windows uses \r\n as the line terminator while Linux (and most other operating systems) use \n alone. When you edit a file in Windows, Windows will add \r to the end of the lines and that will break your scripts.
The character '\r' is carriage return. It returns the cursor to the start of the line.
You should be able to do it with sed
like this:
sed 's/\r//g' orig.txt > modified.txt
In case you are using the terminal on a mac, use this instead to be able to recognize \r
sed "s/$(printf '\r')\$//" orig.txt > modified.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With