linux study notes 3 ------ shell ------- sed

Format: sed [options] '[action]' filename

------------------ options: ------------------------------ ------------------------

-n sed command will output to the screen all the data, the output of this option will sed after treatment to the screen.

-e applied to input data allows multiple commands to edit sed

-I directly modify the data file

---------------------------------------------------------------

Multi-line: with [\] divided such sed '2,4a drink tea or \ drink beer \ or drink coffee' append line 2-4 in row 3: drink tea, drink beer, or drink coffee

----------------------------------------------action:-- ---------------------

adding a number of rows is a front, a back to append characters, the string will be added after the specified row. As 3anewline added after line 3 newline;

sed -i 3anewline testfile.txt

Alternatively the front row is the row number c c, c is the later to be replaced character, will

i is the row number i is inserted in front of, behind the i character is to be inserted; eg: 2inewline prior to line 3 (line 2) is inserted newline nl / etc / passwd | sed '3inewline'

Before d d is the number of rows to delete, delete without adding character; eg: 3d Delete Line 3: nl / etc / passwd | sed '3d' nl line numbers,

nl / etc / passwd | sed '2,5d' delete lines 2-5; delete 2 to the last line ($): nl / etc / passwd | sed '2, $ d'

p printout

Alternatively string s, s row range format / old string / new string g

nl /etc/passwd | sed  '/root/p:

First passwd will output all lines, then the output will be matched to the / root line.

 

Guess you like

Origin www.cnblogs.com/fangxiaosheng/p/11640374.html