sed command line Editor
SED is a non-interactive editor that processes object files by row, but does not modify the processing file itself, but instead reads the contents of the file row by line and saves the copy in a temporary buffer and processes it. Processing completes each row to print the row target content to the screen, deletes the cache content, and then reads the next line for processing. It is also important to note that, unlike grep, SED has an exit status of 0 regardless of whether the specified pattern is known (Linux usually represents true). The exit status of SED is not 0 unless there is a syntax error.
Double quotes are not used in single quotes
The original file is modified by default,
-N Silent Display
-I modify source file
-E Script
-f Specifies the file, which can have scripts
Sed-f/path/Script path file specified
-R Using Extended expressions
My raw material.
Var.txt
Yum_list
"About delimiter" and find content conflict can be used//, @ @ @, # # #
W command
"Delete Row management" D
Delete the second line sed ' 4d ' var.txt
Delete the second line to the last line sed ' 4,77d ' var.txt
Delete all rows containing root sed '/root/' d var.txt
Replace all root for LCLg for all sed ' s/root/lcl/g ' var.txt
Delete to the last line sed ' 4, $d ' Ll.txt
Delete + 4 line sed ' 5,+6d ' ll.txt
Remove sed '/^\//d ' fatab starting with a backslash
"Print line Management" p
Display the mode space content and display the conditions of the match bar two times sed '/^\//p ' fatab
Show only the contents of the Sed-n '/^\//p ' Fatab
"Line Append" a
Append new content to the qualifying line
sed '/^\//a \ #hello world ' fstab/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1#hello wordUUID=5dbd32f9-d400-4e24-a7fa-af5199575fe1 /boot ext4 defaults 1 2/dev/mapper/VolGroup-lv_home /home ext4 defaults 1 2#hello word/dev/mapper/ volgroup-lv_swap swap &nBsp; swap defaults 0 0#hello wordtmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs Defaults &nbsP; 0 0
I'm going to add two lines.
Sed '/^\//a \ #hello \ n Linux ' Fstrab
"Append line before match to" I
Use the same method as a
"Append the contents of a file below the line matched to," or to merge files
Under Line 5th, append the aaaa in the current path to sed ' 5r aaaaa ' Fastab
[[email protected] home]# sed ' 4r aaaaaa ' fstab ## /etc/fstab# created by anaconda on fri jun 5 18:17:35 2015423423894u234u2p93423423423523523523523## accessible filesystems, by reference, are maintained under '/dev/disk ' # see man pages fstab (5), findfs (8), mount (8) and/or blkid (8) for more info#/dev/mapper/volgroup-lv_root / ext4 defaults 1 1UUID=5dbd32f9-d400-4e24-a7fa-af5199575fe1 /boot ext4 defaults 1 2/dev/mapper/volgroup-lv_home /home ext4 defaults 1 2/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0tmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs defaults 0 0proc /proc proc defaults 0 0
Append the contents of this file to line 5th through 7th.
Sed ' 5,7raaaaa ' fastabsed ' 5,7r aaaaa ' fastab This space is not all you can
W Save As
Matches the oot in Fastab and saves it to the Haha.txt file under the current path, which is also displayed by default
Sed '/oot/w haha.txt ' Fatab
Plus-n will not show the default
Sed-n '/oot/w haha ' fstab
"s Replace"
Replace the oot in Fstab with Oot.
Sed ' s/oot/oot/' fstab
I put fstab, each line first appeared slash/replace with #, note the escape character
Sed ' s/\//\#/' fstab
Slash/do processing only for the beginning of the line
Sed ' s/^\//\#/' fstrab
G Replace the found match with a/replace with #
Sed ' s/\//\#/g '
I ignore case, same as G usage
"Regular expression"
& references the entire string, no matter how long the preceding string
A regular expression that references a pattern, a back-reference
Source file Contents
Hello, like
Hi, My Love
Execute command sed ' s#l. E#&er#g ' Sed.txt
or perform sed ' s#\ (L. e\) #\1er#g ' Sed.txt
Hello, Likeer.
Hi, My Loveer
Match and modify the file
Encounter a match pattern, just modify one part of what to do
Can match to L. e expression, instead of L. EEr
Sed ' s#l\ (.. e\) #L \1er#g ' Sed.txt
Hello, Likeer.
Hi, My Loveer
-R Using Extended expressions
You delete the front space of the history
History | Sed ' s#[[:space:]]*# #g ' no matter how many spaces you have at the beginning of the line, you can erase them.
Show the first paragraph of the history command page
History | Sed ' s#^[[:space:]]*# #g ' | Cut-d '-f1
This article comes from "Life is endless, tossing and turning." "blog, declined reprint!"
sed command line editor "original"