Thursday, April 28, 2022

[SOLVED] How to remove \r character with sed

Issue

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


Solution

You should be able to do it with sed like this:

sed 's/\r//g' orig.txt > modified.txt


Answered By - Wiktor Stribiżew
Answer Checked By - Gilberto Lyons (WPSolving Admin)