sedLinux system is a good file processing tool, you can replace the data, delete, new and select the operation, the use is also very important, the following is a comprehensive SED operation introduction.
sed command-line format: sed [options] ' command ' file (s)
Options Common options:
- N or--quiet or--silent: Displays only the results after the script is processed;
- e : Processes the input text file with the specified script in the option;
- F : Process The input text file with the script file specified in the option;
-r:sed the action supports the grammar of the extended formal notation;
- I.: directly modify the contents of the file read, not by the screen output;
- H or--help: Display Help;
- v or--version: Displays version information.
Command Common commands:
a : New, A can be followed by a string, and these strings will appear on a new line (the current next line);
C : Replace, C can be followed by strings, these strings can replace the line between n1,n2;
D : Delete, usually does not pick up any strings after D;
I : Insert, I can be followed by strings, and these strings will appear on a new line (the current line);
P : Print, that is, print out a selected material. Normally p will work with parameter sed-n;
s : Replace, work that can be replaced directly, usually in conjunction with regular expressions.
Example Description:
New action: a command
sed '/^bird/a\test ' file append test to the line beginning with Bird
Delete operation: D command
sed '/^$/d ' file # delete blank lines;
sed ' 2d ' File # delete the second row;
sed ' 2, $d ' File # Delete line 2nd to last row;
sed ' $d ' file # delete the last line;
sed '/^bird/' d file # Delete all rows beginning with bird;
Insert operation: I command
sed-i ' 3i\bird ' bird.conf # Insert Bird before line 3rd of the bird.conf file
Replace string in text: s command
sed ' s/bird/birds/' file # replace the bird in the text with the birds;
sed-i ' s/bird/birds/g ' File # Replace the first bird of each row in the file files with birds;
The above is a simple syntax introduction and application of the Linux sed command, more usage also needs to be found and used in the work constantly!
Linux 0 Basic Learning linux SED command common operation detailed