I need to replace thousands of carriage returns/line breaks in a large xml file and with spaces. I hope to do so with a script, called, for example, "removeCRs." I would invoke this at the command line as
ml5003$ sed -f /Users/ml5003/removeCRs oldFile > newFile
The script, I presume, would be
s/symbol for carriage return/ /g
My question is how do I express a carriage return in the script file? I am using pico as my text editor on a MAC OS X.
Please advise and thanks,
ml5003
You could do it easily with tr:
tr -d '\r' < infile.txt > outfile.txt
Just in case the OP means dos files, try dos2ux which is meant to transform windows files into unix files. What Glen posted does the same thing - it removes all ^M characters, but not just ones at the end of a line.
If you have to use sed,this one assumes every lines ends with cr/lf
sed 's/.$//'
That's a good point, Jim. Thanks for pointing that out. More specifically, you could use tr to remove carriage returns only if they occur at the end of a line by doing:
tr -d '\r$' < infile.txt > outfile.txt
Whooops.
Why do you want to turn ^M into spaces?