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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-26-2006
d__browne d__browne is offline
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
  #2 (permalink)  
Old 04-26-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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.
  #3 (permalink)  
Old 04-26-2006
d__browne d__browne is offline
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
  #4 (permalink)  
Old 04-26-2006
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 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
  #5 (permalink)  
Old 04-26-2006
Raom Raom is offline
Registered User
  
 

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

as simple as this
sed -e 's/ptrn/newptrn/g' file
  #6 (permalink)  
Old 04-26-2006
d__browne d__browne is offline
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
  #7 (permalink)  
Old 04-26-2006
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 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
Closed Thread

Bookmarks

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 07:48 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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