Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with SED command

Status
Not open for further replies.

calredd

IS-IT--Management
May 30, 2006
2
US
Hi gurus,
I am struggling with a small sed command and thought I could use some of your expertise. I need to replace
the very first occurance of start and end brace with say for ex: XYZ. I have given example below. Appreciate your inputs.
Thanks
Carl

Input:

string (replace) after and after ( dont replace ) ; ( dont )
string (replace) after ( ) ; ( asdf )

string (replace) after and after ( dont replace ) ; ( not to be replaced )

******************************************************
Output:

string (XYZ) after ( stuff ) ; ( asdf )
decimal (XYZ) after ( ) ; ( asdf )

string (XYZ) and after ( stuff ) ; ( )
 
Something like this ?
sed 's!([^)]*)!(XYZ)!' /path/to/input > output

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Just to add my 2 cents.

You could also put the number of the occurance that you wanted to change. Something like...
Code:
sed 's!([^)]*)!(XYZ)![b]1[/b]' /path/to/input > output
This means you can change the second or third occurrance only if you want...
Code:
sed 's!([^)]*)!(XYZ)![b]2[/b]' /path/to/input > output
This would change only the second parenthesis.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top