The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-25-2008
sohaibs sohaibs is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
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.
  #2 (permalink)  
Old 11-25-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
Should be something like:

Code:
sed 's/,null,/, ,/g' result.txt > result.tmp
  #3 (permalink)  
Old 11-25-2008
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Quote:
Originally Posted by sohaibs View Post
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.
Doesn't this work ?

Code:
sed -e "s/,null,/, ,/g" result.txt > result.tmp
  #4 (permalink)  
Old 11-25-2008
sohaibs sohaibs is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
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.
  #5 (permalink)  
Old 11-25-2008
Franklin52 Franklin52 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,212
It should work, post your file within code brackets (select the code and click on the "#" above the editing window).

Regards
  #6 (permalink)  
Old 11-25-2008
sohaibs sohaibs is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
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
  #7 (permalink)  
Old 11-25-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,257
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
Edit:
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
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:06 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0