Beginning sed

Dec 16 2011 Published under Linux,Programming | Tags:

The essential command: s for substitution

$ echo dayTime | sed 's/day/night/' 
nightTime

& corresponds to the pattern found:

$ echo abc | sed 's/abc/(&)/'
(abc)

* wildcard will try to match zero or more characters:

$ echo "123" | sed 's/[0-9]*/(&)/'
(123)

Be careful as * wildcard is made to be as greedy as possible, that’s why the following example will output something not as expected at first glance:

$echo "a123" | sed 's/[0-9]*/(&)/' 
()a123

A better approach to is:

echo "a123" | sed 's/[0-9][0-9]*/(&)/' 
a(123)

ref:
http://www.grymoire.com/Unix/Sed.html#uh-0

Tags:

No responses yet

Comments are closed at this time.

Login