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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-28-2007
bobo bobo is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 148
Unhappy sed question

I have this line "%is xxx = 123" in a program. I want to use sed command to replace it with something else but part of this line is not the same all the time. For example, it could be "%is xxx = 456" (and these three number change all the time)

I have:

sed 's/%is xxx = 123/my replacement/g' programfile > newfile

What modify I need to do to have it works wether it /%is xxx = 123, /%is xxx = 456 or so? I know ^ this begin of the line and $ is end of the line

sed 's/%is xxx = ***$/my replacement/g' programfile > newfile

Please advise!

Thanks!
  #2 (permalink)  
Old 03-01-2007
mona's Avatar
mona mona is offline
Registered User
  
 

Join Date: Nov 2005
Location: Singapore
Posts: 96
Will this help?

Code:
$ cat tmp
%is xxx = 123
$ sed 's/^\(%is xxx = \)[0-9]*\( *.*\)$/\11234\2/g' tmp
%is xxx = 1234
  #3 (permalink)  
Old 03-01-2007
bobo bobo is offline
Registered User
  
 

Join Date: Jan 2006
Posts: 148
Unhappy

What happen if the data is
$ cat tmp
%is xxx = 123 be 123
How to code it so it will ignore 123 be 123. I know that "%is xxx = " is the exact pattern everytime the rest of the line is unknown
using the code below I will get
$ sed 's/^\(%is xxx = \)[0-9]*\( *.*\)$/\11234\2/g' tmp

%is xxx = 1234 be 123

I am only interested to get:
%is xxx = 1234
  #4 (permalink)  
Old 03-01-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Remove \2
Code:
$ sed 's/^\(%is xxx = \)[0-9]*\( *.*\)$/\11234/' tmp
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 06:52 PM.


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