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
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 07:24 AM
Search and Replace in Ksh DeepakXavier Shell Programming and Scripting 9 05-28-2007 05:11 AM
how to search for a str and replace it.. sekar sundaram Shell Programming and Scripting 6 12-29-2005 03:11 PM
Search and replace sed or tr bridgeje Shell Programming and Scripting 6 10-28-2003 04:54 AM
search and Replace mukeshannamalai UNIX for Advanced & Expert Users 4 09-14-2001 03:21 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 04-26-2006
Registered User
 

Join Date: Mar 2006
Posts: 20
sed search and replace

Hello Folks,

Anyone know how I can replace this line in file.xml

<oacore_nprocs oa_var="s_oacore_nprocs">8</oacore_nprocs>

with this line

<oacore_nprocs oa_var="s_oacore_nprocs">1</oacore_nprocs>

using sed or awk ?

Thanks for your time.

Cheers,

Dave
Reply With Quote
Forum Sponsor
  #2  
Old 04-26-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Code:
sed -e "s/\(<oacore_nprocs [^>]*>\)[^<]*\(<.*\)/\1SOME-TEXT-TO-GO-IN\2/g"
The sed expression could get simpler. But this one would take anything between the tags and replace it with SOME-TEXT-TO-GO-IN.
Reply With Quote
  #3  
Old 04-26-2006
Registered User
 

Join Date: Mar 2006
Posts: 20
Hi thanks for the reply.
I'm not sure I understand the command, I just need to replace the 8 with the 1 on that particular line in file.xml
Will this do that ? I cant see how it will.
Thanks
Reply With Quote
  #4  
Old 04-26-2006
Registered User
 

Join Date: Sep 2005
Location: india
Posts: 78
Talking

as simple as this
sed -e 's/ptrn/newptrn/g' file
Reply With Quote
  #5  
Old 04-26-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Quote:
Originally Posted by vino
Code:
sed -e "s/\(<oacore_nprocs [^>]*>\)[^<]*\(<.*\)/\1SOME-TEXT-TO-GO-IN\2/g"
The sed expression could get simpler. But this one would take anything between the tags and replace it with SOME-TEXT-TO-GO-IN.

Replace SOME-TEXT-TO-GO-IN with 1
Reply With Quote
  #6  
Old 04-26-2006
Registered User
 

Join Date: Mar 2006
Posts: 20
tried both suggestions, neither worked.

sed -e "your_command" file.xml

just cats the file and does nothing
Reply With Quote
  #7  
Old 04-26-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,683
Quote:
Originally Posted by d__browne
tried both suggestions, neither worked.

sed -e "your_command" file.xml

just cats the file and does nothing
Ofcourse, it will not write to the xml file. You need to redirect it and then move it to the original.

Something like

Code:
sed -e "your_command" file.xml > file.xml.new
mv file.xml.new file.xml
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:16 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