The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-09-2006
Registered User
 

Join Date: Jun 2006
Posts: 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
Reply With Quote
Forum Sponsor
  #2  
Old 06-09-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
You could do it easily with tr:

Code:
tr -d '\r' < infile.txt > outfile.txt
Reply With Quote
  #3  
Old 06-09-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
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/.$//'
Reply With Quote
  #4  
Old 06-09-2006
Glenn Arndt's Avatar
Anomalous Lurker
 

Join Date: Feb 2006
Location: Indianapolis, IN
Posts: 255
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
Reply With Quote
  #5  
Old 06-09-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
Whooops.

Why do you want to turn ^M into spaces?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:12 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0