understanding sed patterns
How are patterns in sed handled in this situation?
source: http://gilmation.com/articles/regexp...attern-in-sed/ The following example finds words surrounded by the same number (ab is surrounded by 1 and ef is surrounded by 82) and removes the surrounding number: Code:
$ echo "4 9 1 ab 1 cd 13 82 ef 82" | sed 's/\([0-9]*\) \([a-z]*\) \1/\2 /g' Code:
4 9 ab cd 13 ef |
The substitute command is s/// as in
Code:
s/old/new/ So if you have a pattern along the lines of 'A B A' then it is replaced with 'B' |
Hey, don't delete stuff. Someone searching for a similar problem won't see the key part when this thread turns up in their search results.
|
Sorry, I didn't know how to handle it :) It was actually much easier than I had thought and I deleted it before you replied, otherwise I wouldn't have deleted it. I'll just rewrite the post then.
|
Thanks.
|
I had interpreted the slash between \1 and \2 as the third occurrence, because I hadn't seen \1 in the first part of the substitution before, and I automatically thought that there was a another slash before \1. Thanks.
|
All times are GMT -5. The time now is 03:49 PM. |