Saturday, August 30, 2008

sed

sed command is used to search and replace the word.
eg:
sed "s/old/new/g" filename

This command find and replace the word old with new globally.

Search and Replace specific lines only.

sed '1,3s/a/A/g' filename
Above command replace the 'a' with 'A' in first three lines in the file.

Input a square brackets.
sed 's/[A-Z]/[&]/g' filename

To print '*' at the beginning of files those contain capital letters
sed '/[A-Z]/s/^/*/' filename

No comments: