Linux 0 Basic Learning linux SED command common operation detailed

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.