2009/2/5

Usage sed and regular expression

sed - stream editor for filtering and transforming text
important argument:
-e -> add the script to the commands to be executed
-f -> add the contents of script-file to the commands to be executed
-i -> edit files in place (makes backup if extension supplied)

find the word "test.jpg" and replace to "qwer.jpg" in file plot.com
sed 's/".*\.jpg"/"testtest\.jpg"/' plot.com

.* -> any word
\. -> Escaped word "."
s/haha/nana/ -> replace the word haha to the word nana once
s/haha/nana/g -> replace the word haha to the word nana every time