News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Linux Programming Tutorial: Using SED to Edit strings in a File in Linux

Started by VelMurugan, Dec 16, 2008, 05:39 AM

Previous topic - Next topic

VelMurugan

Linux Programming Tutorial: Using SED to Edit strings in a File in Linux

string editor, sed, is used for editing lines in a file or a stream; output is going to the standard output and can be re-directed to a
new file.
Quote
syntax: sed [options] 'command1' [files]
            sed [options] -e 'command1' [-e command2 ...] [files]
            sed [options] -f script [files]

delete lines from 3 through 5 in file list.txt:
sed '3,5d' list.txt

delete lines that contain "o" at the beginning of the line:
sed '/^o/d' list.txt

translate capital c,r,o into small c,r,o:
sed 'y/cro/cro/' list.txt

delete ampty lines:
sed '/^$/d' list.txt

replace string oop with wee for the first occurence on a line
sed 's/oop/wee/' lsst.txt

remove ss string (replace with empty entry)for the first occurence on a line:
sed 's/ss//' list.txt

remove ss string for all occurences on a line:
sed 's/ss//g' list.txt

substitute a single space for any number of spaces wherever they occur on the line:

sed 's/ */ /g' list.txt

substitute underscore for any number of spaces wherever they occur on the line:
sed 's/ */_/g' list.txt

Source : ExpertsForge