![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#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 |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|