|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | 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 Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Search and replace command
Hi, I wanted to replace the character '~' with \n (carraige retrurn or new line character) I am tried the commands like Code:
s/~/\n/g s/~//\n/g but the commands says that no "No match exists for the substitute pattern". Last edited by methyl; 06-22-2012 at 07:19 AM.. |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
sed 's/~/\ /g' |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Hi, Thanks for your reply, But I dont see any carriage return character metioned in your command. Moreover I tried the command that you provided but i dont see the result. Could you please suggest me anyother ways of doing it. My i/p file will look like Code:
ISA*00**00**02*CN*ZZ*RECEIVERID*060628*0035*U*00201*000000612*0*P*> ~GS*IM*CN*APPLICATION RECEIVER ID*20060628*0035*612*X*004010 ~ST*210*612001~B3*B*28061234*102141*PP**20060628*208360****CNRU ~N1*PR*PAYERNAME*25*772305B~N3*123NEWBRIDGEROAD .~N4*ETOBICOKE*ON ~N1*CN*CONSIGNEENAME*25*772305~N3*1800INKSTERBLVD~N4*WINNIPEG SYMING YAR*MB*R2X2Z5 ~N1*SF*SHIP FROM NAME*25*772305 ~ I have change this as Code:
ISA*00**00**02*CN*ZZ*RECEIVERID*060628*0035*U*00201*000000612*0*P*> GS*IM*CN*APPLICATION RECEIVER ID*20060628*0035*612*X*004010 ST*210*612001 B3*B*28061234*102141*PP**20060628*208360****CNRU N1*PR*PAYERNAME*25*772305B N3*123NEWBRIDGEROAD . N4*ETOBICOKE*ON N1*CN*CONSIGNEENAME*25*772305 N3*1800INKSTERBLVD N4*WINNIPEG SYMING YAR*MB*R2X2Z5 N1*SF*SHIP FROM NAME*25*772305 Last edited by methyl; 06-22-2012 at 07:15 AM.. Reason: Please use code tags. |
|
#4
|
||||
|
||||
|
You see the back-slash in the command? Right after it, I have pressed Enter (or Return). So, I am escaping the newline and telling sed to treat it as a new-line character for replacement...
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
It gives syntax error for when I execute it in a script as you have mentioned.
|
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Try the unix
tr command: Code:
cat inputfile | tr '~' '\n' > outputfile I get a virtually perfect match to your sample output (including sporadic trailing space characters), except that the very last ~ causes a trailing blank line in the output file. Last edited by methyl; 06-22-2012 at 08:00 AM.. Reason: typos in wording |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Elixir_sinari's suggestion should work fine. Make sure the backslash is the very last character on the first line. Alternative sed that does allow \n : Code:
sed 'y/~/\n/' infile |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| search and replace with sed command | divya bandipotu | Shell Programming and Scripting | 2 | 06-16-2011 04:21 AM |
| awk - replace number of string length from search and replace for a serialized array | otrotipo | Shell Programming and Scripting | 1 | 07-10-2009 12:04 PM |
| How to search and replace a particular line in file with sed command | sshah1001 | UNIX for Dummies Questions & Answers | 2 | 05-30-2009 10:45 PM |
| SED command to search for numeric and replace | ajayh | UNIX for Dummies Questions & Answers | 1 | 04-16-2009 01:35 PM |
| sed search and replace command | janzper | Shell Programming and Scripting | 1 | 01-26-2009 10:49 AM |
|
|