By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,660 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,660 IT Pros & Developers. It's quick & easy.

sed and awk Question

P: 4
Questions:

1) Using sed, how would you do a pattern replacement if the pattern contains slashes?

Example:

Input Pattern is /w585/odbi/BCPWK/DOCGET/
Output Pattern is blank

sed -i 's//w585/odbi/BCPWK/DOCGET///' filename

When I use the above command I get the following error:
sed: -e expression #1, char 9: unknown option to `s'

2) Can you do a in place edit using awk?

Thank you
Feb 22 '08 #1
Share this Question
Share on Google+
1 Reply

prn
Expert 100+
P: 254
prn
Questions:

1) Using sed, how would you do a pattern replacement if the pattern contains slashes?

Example:

Input Pattern is /w585/odbi/BCPWK/DOCGET/
Output Pattern is blank

sed -i 's//w585/odbi/BCPWK/DOCGET///' filename

When I use the above command I get the following error:
sed: -e expression #1, char 9: unknown option to `s'

2) Can you do a in place edit using awk?

Thank you
Try "escaping" the slashes in the pattern using a preceding backslash, e.g.,

sed -i 's/\/w585\/odbi\/BCPWK\/DOCGET\///' filename

I don't have my SED references here, so I'm not sure if you can use alternate pattern delimiters in SED. You certainly can in Perl, which makes patterns like that much easier to read. I also have not used awk for a number of years so I am not sure about in place editing with awk. I think you may be able to do that.

Although I don't want to play the language bigot and say that Perl is the answer to everything, again, you can do it easily in Perl. Google for "perl edit in place" and you will find useful information.

HTH,
Paul
Feb 24 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.