Jim Cheung

http://www.grymoire.com/Unix/sed.html

replace

sed 's/one/ONE/' <file

different delimiter

sed 's:/usr/local/bin:/common/bin:' <old >new

use matched string as replacement, with &

% echo "123 abc" | sed 's/[0-9][0-9]*/& &/'
123 123 abc

if need to use +, turn -r on

% echo "123 abc" | sed -r 's/[0-9]+/& &/'
123 123 abc

\1 is the first remembered pattern, then \2 ... \9

sed 's/\([a-z]*\).*/\1/'

pattern flags:

| /g          | global replacement          |
| /1, /2, etc | specifying which occurrence |
| /p          | print                       |
| /w filename | write to filename           |
| /I          | ignore case                 |

    sed -n 's/^[0-9]*[02468] /&/w even' <file

arguments:

| -e | multiple commands |
| -n | no printing     |
| -f | use script file |

    sed -e 's/a/A/' -e 's/b/B/' <old >new