Preface: Sed Is A Street.it Can Edit A File OR Data, And It Just Modify The ORIGINALLY Files.
Format of Sed: $ SED 'COMMAND' FileName.
Command functions:
A: appends one or more liss of text to the current line.
C: Changes (replaces) Text in the current line with new text.
D: DELETES LINES.
E: More Than One Command.
I: INSERTS TEXT ABOVE The Current Line.
H: Copies The Contents of the Pattern Space To a Holding Buffer.
H: appends the contents of the pattern space to a holding buffer.
G: Gets what is in the holding buffer and copies it inte the pattern buffer, overwriting what..
G: gets what is in the holding buffer and copies it info the pattern buffer, appending to what...
l: lists nonprinting character.
P: PRINTS LINES.
N: Reads the next input.
S: Substitutions One String for Another.
Q: Quits or exits sed.rreads lans from a file.
!: Applies The Command To All Lines Except The SELECTED Ones.
Substitution Flags:
G: Globally Substitute on a line.
P: PRINTS LINES.
W: WRITES LINES OUT to A File.
X: Exchanges Contents of The Holding Buffer with the pattern space.
Y: Translates One Character To Another (Cannot Use Regular Expression Metachacters with Y).
1) $ SED '1,3p' Myfile
IT WILL PRINTS All Lines of Your File.
2) $ SED -N '1,3p' Myfile
IT WILL PRINTS 1-3 LINES OF THE FILE.
3) $ SED '1,3d' Myfile
IT Will deletes The Lines from 1 to 3 of your file.
4) $ SED '/ TOM / D' DATAFILE
IT Will deletes the line contacts / Tom / pattern.
5) $ SED '/ TOM /! D' DATAFILE
IT WILL DELETES The Line Dont Contains / Tom / Pattern.
6) $ SED 'S / 12345 // g DataFileit Will Change The 12345 to space of nothing with the goalble range.
7) $ SED '3, $ D' DATAFILE
8) $ SED -E '1,3d' -e 's / helmenway / jones /' datafile
9) $ SED '/ SUAN / R NEWFILE' DATAFILE
PS: r means read newfile.
10) $ SED '/ LEWIS / {S / LEWIS / JOSEPH /; Q;}' DataFile