Introduction to SED
Sed is String
editor, Its used for editing lines in a file or a stream; Output re-directed to a new file or we can re-direct as a standard output.
Syntax:
sed [options] 'command1' [files]
sed [options] -e
'command1' [-e command2 ...] [files]
sed [options] -f
script [files]
Delete
lines from 4 through 6 in file page.txt:
sed '4,6d' page.txt
Delete
lines that contain "P" at the beginning of the line:
sed '/^P/d' page.txt
Translate
capital R,T,O into small r,t,o:
sed 'y/CRO/cro/' page.txt
Delete empty lines:
sed '/^$/d' page.txt
Replace
string C++ with Java for the first occurence on a line
sed 's/C++/Java/' page.txt
Remove pp string (replace with empty entry)for the first occurence on a line:
sed 's/pp//' page.txt
Remove
ss string for all occurences on a line:
sed 's/pp//g' page.txt
Substitute
a single space for any number of spaces wherever they occur on the
line:
sed 's/ */ /g' page.txt
Substitute
underscore for any number of spaces wherever they occur on the
line:
sed 's/ */_/g' page.txt
No comments:
Post a Comment