Computing.Net > Forums > Unix > replace a complex string using sed

replace a complex string using sed

Reply to Message Icon

Original Message
Name: may
Date: December 2, 2003 at 07:42:54 Pacific
Subject: replace a complex string using sed
OS: W2K
Comment:

Hello,
I want to replace in a file a string with another string like the example:

file name: Test
String1 = ggggg (exist in the file Test)
String2 = /tcwork/nirgr/fffff


the following doesn't work because of the slash:
sed 's/gggg/ /tcwork/nirgr/fffff /g' Test

Do you have any idea?

Thanks may


Report Offensive Message For Removal

Response Number 1
Name: Nails
Date: December 2, 2003 at 13:32:22 Pacific
Subject: replace a complex string using sed
Reply: (edit)

Hi:

You need to escape the slashes:

sed 's/gggg/ \/tcwork\/nirgr\/fffff /g' Test

Regards,

Nails


Report Offensive Follow Up For Removal

Response Number 2
Name: David Perry
Date: December 4, 2003 at 05:57:19 Pacific
Subject: replace a complex string using sed
Reply: (edit)

Or you can use different delimeter characters for sed.

sed -e 's,gggg,/tcwork/nirgr/fffff,g' Test



Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: replace a complex string using sed

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software