The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 07:10 AM
SSH Problem auth problem budrito UNIX for Advanced & Expert Users 1 03-17-2004 07:12 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 05-09-2007
Registered User
 

Join Date: May 2007
Posts: 1
linefeed problem

I have a file in which I need to remove all newline characters but only if they are preceded by "^C" ( ASCII value 3 )

Basically this is a bulk copy file with "^B" and "^C" as delimiters for each record. The application producing the file is also appending a newline which I need to remove, however there is the potential for newline characters to also exist within the body of each record and these must not be touched.

E.G. If myfile contains :

^Babc123^C
^Bxyz
987^C
^Bfoobar^C

I need to convert to :

^Babc123^C^Bxyz
987^C^Bfoobar^C

See how it maintains the newline after "xyz" but supresses the others ?

Obviously I can't use tr '\010' '' because that gets rid of the embedded linefeed that I have to keep. I tried to use sed as follows :

cat myfile | sed 's/^C\\n/^C/' > mynewfile

That doesn't work because apparently sed strips the newline for each record it reads in before applying the substitution.

Any bright ideas ? I'm guessing that it may need some black art like nawk
Reply With Quote
Forum Sponsor
  #2  
Old 05-09-2007
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,275
Try this - note not all seds allow \xnnn for a hex number:
Code:
sed -e :a -e '/\x003$/N; s/\x003\n//; ta' oldfile > newfile
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




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


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