![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Replacing Carriage returns without loosing EOL | Majiktom | Shell Programming and Scripting | 2 | 03-08-2008 04:28 AM |
| Removing carriage returns with sed | stevefox | Shell Programming and Scripting | 12 | 01-25-2006 10:02 PM |
| Remove Carriage returns between strings in a field | acheepi | Shell Programming and Scripting | 10 | 09-24-2005 10:19 AM |
| spaces and carriage returns in 'here documents' | hcclnoodles | Shell Programming and Scripting | 0 | 04-11-2005 03:49 AM |
| sed removing carriage return and newline | mored | Shell Programming and Scripting | 2 | 05-06-2004 09:28 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
removing thousand of carriage returns using sed
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
You could do it easily with tr:
Code:
tr -d '\r' < infile.txt > outfile.txt |
|
#3
|
|||
|
|||
|
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 Code:
sed 's/.$//' |
|
#4
|
||||
|
||||
|
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:
Code:
tr -d '\r$' < infile.txt > outfile.txt |
|
#5
|
|||
|
|||
|
Whooops.
Why do you want to turn ^M into spaces? |
|||
| Google The UNIX and Linux Forums |