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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed script to find and replace a string of text

Status
Not open for further replies.
Dec 13, 2002
109
GB
Hello
I am looking for a sed script that can search through a file and replace a string that starts with a certain letter and ends with a fulls stop for a fixed string.
For example:

Hello world, I am ronaldmacdonald.

This is the repalcement string.

So in the above I want to replace all occurrunces of the string that start with "H" and end with "." with the text "This is the repalcement string."

Is this possible?

Thanks
 
Hi

Like this ?
Code:
sed 's/^H.*\.$/This is the repalcement string./' /input/file
( If you like the above command's output, you may add a [tt]-i[/tt] option to alter the input file directly. )


Feherke.
[link feherke.github.com/][/url]
 
Yes that looks likeit would be ok, sadly I am using sed for windows which isn't as forgiving as the sed for unix so I need to tweak that up a bit but thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top