1: Comment out a line
This is often encountered, the configuration file in a line to comment out. Let him not work.
sed-i-E ' 121 s/^/#/'/usr/local/apache2/conf/httpd.conf
the meaning of the above line of command is to comment out the 121 lines.
sed-i-E ' 121 s/^/#/'-i-e ' 122 s/^/#/'/usr/local/apache2/conf/httpd.conf
This is to comment out 121,122 lines.
2: Remove the note # to make this line work
Sed-i ' s/#ServerNamewww.example.com:80/ServerNameWww.example.com:80/g '/usr/local/apache2/conf/httpd.conf
The order is to get rid of this line of #. is actually a replacement process.
3: Insert a row at the position of a line
If you just append a row to a document, it's simple. >> can take care of it. However, if it is inserted in a specified line.
Sed-i "8 S/^/alias vi= ' vim '/"/ROOT/.BASHRC
is to insert alias vi= ' vim ' in line 8th
4: How to insert a line, including special characters/
Sed-i "S/^/addtype application\/x-httpd-php. php. phtml/" httpd.conf
This lets Apache support PHP, much simpler.
The following usage has not been tested. Another test.
Sed:
1. Delete the beginning of the line space
Sed ' s/^[]*//g ' filename
Sed ' s/^ *//g ' filename
Sed ' s/^[[:space:]]*//g ' filename
2. Add new lines after line and before line
After line: sed ' s/pattern/&\n/g ' filename
Before line: sed ' s/pattern/\n&/g ' filename
& Representative Pattern
3. Use variable substitution (using double quotes)
Sed-e "s/$var 1/$var 2/g" filename
4. Insert text before the first line
Sed-i ' 1 i\ insert string ' filename
5. Insert in last line
Sed-i ' $ a\ insert string ' filename
6. Insert before matching line
Sed-i '/pattern/i ' Insert string ' ' filename '
7. Insert after matching line
Sed-i '/pattern/a "Insert string" ' Filenam
The customary use of SED