![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | 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 !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unix Arithmatic operation issue , datatype issue | thambi | Shell Programming and Scripting | 23 | 02-19-2008 07:19 AM |
| Need Replacement for sed | dbsurf | Shell Programming and Scripting | 0 | 01-25-2008 06:47 PM |
| Text replacement between 2 files | bobo | UNIX for Dummies Questions & Answers | 3 | 09-10-2007 09:13 PM |
| Awk/Sed One liner for text replacement | bishnu.bhatta | UNIX for Dummies Questions & Answers | 5 | 03-26-2007 01:51 AM |
| Replacement using sed | handak9 | UNIX for Dummies Questions & Answers | 5 | 07-13-2004 11:28 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Sed text replacement issue.
Hi,
Im trying to find and replace text within a unix file using sed. The command that i have been using is sed '/,null,/ s//, ,/g' result.txt>result.tmp for replacing ",null," with ", ,". But this only replaces the first occurrance of ,null, in every line. I want to do it globally. It works fine if i exclude all the commas. Please help. |
|
||||
|
sed -e "s/,null,/, ,/g" result.txt > result.tmp
sed 's/,null,/, ,/g' result.txt > result.tmp Both the above statements only replace the first occurance of ,null, to , , in each line. Could this be done in any other way? Im trying to modify the contents of a file using a shell script that first extracts this data and modifies it a bit. |
|
||||
|
Code:
2,520,DB_MSC_MIT,null,KBNY,BLAH,US,5876548,VBU3M.U,VZ0M.U,U,VZFSK,BK,0.772084,ER,10.0,1.0,A,P,1.0,0.0,2009-01-16T00:00:00 @Europe/London,0.0,35.0,To La,1.0,1.6936391,7.07878526,6.629309,242.30009,Amer,1.3309,0.0,0.0,0.0,922.808018,312.3315240926514338,29.83157600000000,574,37.53658120375646,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,-26.10513536513008,0.0,-74951.16306028693,-26.10513536513008,-74925.0579249218,0.0,0.0,0.0,0.0,0.0,0.0,-237.22390960441317,0.0,4896.289228465125,-237.22390960441317,5133.513138069538,0.0,0.0,0.0,0.0,0.0,0.0,-4755.8670072606055,0.0,458181.9339556703,-4755.8670072606055,462937.8009629309,null,null,null,0.0,O,VZFRP JAN 09 35 P,null,null,1.0,null,VP35 1.0,null,null,null,O,BSK,BSK,null,null,DrFr,NY,NY,null,0.0,0.0,0.0,0.0,0.0,0.0,0.0,2,0.0,0.0,0.0 |
|
|||||
|
Both ways are working on my boxes... Though maybe try something like (even I think it is unnecessary):
Code:
sed -e :a -e 's/,null,/, ,/;ta' result.txt Just saw the long example line. With the shown line the 2 sed commands do not work on my boxes - I guess because of the already substituted adjacent commas of following ,null,null. So the loop in sed will be ok. Last edited by zaxxon; 11-25-2008 at 07:15 AM.. Reason: Added info |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Tags |
| shell script, shell scripting, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|