(To make the examples below clearer and less ambiguous, I will use od util .)
This cannot be done with a flag, for example. I bet the best solution is the one quoted from the previous answers: using tr . If you have a file, for example:
$ od -xc slashr.txt 0000000 6261 0d63 6564 0d66 abc \rdef \r 0000010
There are various ways to use tr ; the one we wanted is to pass two parameters to it - two different characters - and tr will replace the first parameter with the second. By sending the contents of the file as input to tr '\r' '\n' , we get the following result:
$ tr '\r' '\n' < slashr.txt | od -xc 0000000 6261 0a63 6564 0a66 abc \ndef \n 0000010
Excellent! Now we can use sed :
$ tr '\r' '\n' < slashr.txt | sed 's/^./#/'
But I suppose you need to use \r as a line separator, right? In this case, just use tr '\n' '\r' to reverse the conversion:
$ tr '\r' '\n' < slashr.txt | sed 's/^./#/' | tr '\n' '\r' | od -xc 0000000 6223 0d63 6523 0d66
source share