Search This Blog

2009-09-22

sed to remove word

Assume I have a string of "(PORT=12)"

Use sed to remove the number

bash-2.05$ echo "(PORT=12)" | sed "s/\(PORT=\)\([0-9]*\)/\1/"
(PORT=)

Use sed to remove the word, and keep the number

bash-2.05$ echo "(PORT=12)" | sed "s/\(PORT=\)\([0-9]*\)/\2/"
(12)

No comments: