Sed (Stream editor) row editor (full screen Editor: VI)
SED: Display mode space
Do not edit the file by default, only the data in the pattern space is processed
Then, after processing is finished, the mode is displayed on the screen
Sed-n ' Addresscommand ' file ...
Single/double quotes can be, double quotation marks can be used to implement variable substitution
-N: Silent mode no longer defaults to display the contents of the mode space
-I: Modify source files directly
-E script-e script: Multiple scripts can be executed at the same time
-f/path/to/sed_script/:
Sed-f path/to/script File
-r: Indicates the use of extended regular expressions
Address:
1. Start line, end line
Like 1,100.
$: Last line
$-1: The first line of the countdown
2./regexp/takes advantage of pattern matching and requires two slashes to be included.
Like/^root.
3./pattrnl/,/pattern2/
The first line that was pattrn1 matched to the end of the line to which the first match was pattrn2, all the rows in the middle
4.LineNumber
The specified row
5. Starting line, +n
From the start line, n rows Backward
Command: Commands
D: Delete rows that match the criteria
P: Show rows that match the criteria
A \string: Appends a new line after the specified line, with the contents of string
I \string: Appends a new line to the specified line, with the contents of string
R file: Adds the specified file contents to the qualifying line
W File: Save the specified file contents to the specified file
s/pattern/string/modifier: Find pattern (available regular expression) and replace with string
(The default is to replace only the first string in each row that is matched to the pattern)
G: Global Substitution
I: Ignore case when finding
S///:s###,[email protected]@@ 也 also be
Delimiters are not limited to/as long as the search for substituted characters is not a delimiter
&: Reference pattern matches entire string
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7D/09/wKiom1beyfCRd7ZtAAB66hF9-wg586.gif "style=" float: none; "title=" Sed1.gif "alt=" Wkiom1beyfcrd7ztaab66hf9-wg586.gif "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7D/07/wKioL1beynLC-OeIAAAsp-wJpLc747.gif "style=" float: none; "title=" Sed2.gif "alt=" Wkiol1beynlc-oeiaaasp-wjplc747.gif "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7D/07/wKioL1beynPDIGqQAABrJLKUx9M070.gif "style=" float: none; "title=" Sed3.gif "alt=" Wkiol1beynpdigqqaabrjlkux9m070.gif "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7D/07/wKioL1beynPT8rZUAABD1QiNbPI516.gif "style=" float: none; "title=" Sed4.gif "alt=" Wkiol1beynpt8rzuaabd1qinbpi516.gif "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7D/09/wKiom1beyfKxS7P_AABqAeA3iI4301.gif "style=" float: none; "title=" Sed5.gif "alt=" Wkiom1beyfkxs7p_aabqaea3ii4301.gif "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7D/09/wKiom1beyfKTb0flAABoIUpoz8c892.gif "style=" float: none; "title=" Sed6.gif "alt=" Wkiom1beyfktb0flaaboiupoz8c892.gif "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7D/07/wKioL1beynTBouhIAACEw_AeWao711.gif "style=" float: none; "title=" Sed7.gif "alt=" Wkiol1beyntbouhiaacew_aewao711.gif "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7D/09/wKiom1beyfOTw2qqAAB8yfcGFx8482.gif "style=" float: none; "title=" Sed8.gif "alt=" Wkiom1beyfotw2qqaab8yfcgfx8482.gif "/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/7D/07/wKioL1beynWxe_2lAABXXImq7Po650.gif "style=" float: none; "title=" Sed9.gif "alt=" Wkiol1beynwxe_2laabxximq7po650.gif "/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7D/07/wKioL1beynbzQmczAABZi2ToqVc988.gif "style=" float: none; "title=" Sed10.gif "alt=" Wkiol1beynbzqmczaabzi2toqvc988.gif "/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7D/07/wKioL1beynawBjlqAACEnx6W94s740.gif "style=" float: none; "title=" Sed11.gif "alt=" Wkiol1beynawbjlqaacenx6w94s740.gif "/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7D/09/wKiom1beyfWzbVwTAAA6zAbuSkU497.gif "style=" float: none; "title=" Sed12.gif "alt=" Wkiom1beyfwzbvwtaaa6zabusku497.gif "/>
Lesson 1: Editing a TXT file
①like-liker Love-lover
②like->like Love->love
Lesson 2: Removing whitespace from the beginning of the/etc/grub.conf file
Lesson 3: Replace the number in the "Id:5:initdefault:" line in the/etc/inittab file with 3
Lesson 4: Deleting blank lines in a file
Lesson 5: Delete the # number at the beginning of a file. (eg: #abc)
Lesson 6: Delete the # and trailing whitespace characters at the beginning of a file, but require a white-space character after #. (# ABC)
Lesson 7: Delete a file with white space followed by white space characters and # at the beginning of the line in the # class. (#abc)
Lesson 8: Take out the parent directory name of a file path
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/09/wKiom1beyj3RJRltAABji4x57o0502.gif "style=" float: none; "title=" 6-2lx1.gif "alt=" Wkiom1beyj3rjrltaabji4x57o0502.gif "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/7D/09/wKiom1beyj3irUeQAACXBnx7jP8466.gif "style=" width : 650px;height:714px; "title=" 6-2lx2.gif "alt=" Wkiom1beyj3irueqaacxbnx7jp8466.gif "height=" 714 "hspace=" 0 "border=" 0 "vspace=" 0 "width=" 650 "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/7D/07/wKioL1beyr-Q92urAABmnVeoYVQ077.gif "style=" width : 650px;height:528px; "title=" 6-2lx3.gif "alt=" wkiol1beyr-q92uraabmnveoyvq077.gif "height=" 528 "hspace=" 0 "border=" 0 "vspace=" 0 "width=" 650 "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/7D/07/wKioL1beysCSETk4AABHjBOtEoQ474.gif "style=" float: none; "title=" 6-2lx4.gif "alt=" Wkiol1beyscsetk4aabhjboteoq474.gif "/>
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/7D/0A/wKiom1be3Sfhep4KAAAoC3B6Tlg807.gif "title=" 6-2lx5 . gif "alt=" Wkiom1be3sfhep4kaaaoc3b6tlg807.gif "/>
This article is from the "11160930" blog, please be sure to keep this source http://11170930.blog.51cto.com/11160930/1748900
2016-3-8 Linux Basic Learning--sed command