469,167 Members | 2,087 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,167 developers. It's quick & easy.

sed and awk Question

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
1 2581
prn
254 Expert 100+
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.

Similar topics

1 post views Thread by Mohammed Mazid | last post: by
3 posts views Thread by Stevey | last post: by
10 posts views Thread by glenn | last post: by
53 posts views Thread by Jeff | last post: by
56 posts views Thread by spibou | last post: by
2 posts views Thread by Allan Ebdrup | last post: by
3 posts views Thread by Zhang Weiwu | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.