SED command application

Source: Internet
Author: User

Sed:stream EDitor, row editor;

Usage: sed [option] ... ' Script ' inputfile ... script: ' Address command ' common options:-N: Do not output the contents of the schema to the screen;-e: Multi-dot
            -f/path/to/script_file: Reading an edit script from a specified file;-r: Supports the use of extended regular expressions;-I: Edit; address delimitation:
            (1) Do not address: The full text of the processing, (2) Single address: #: Specified line;/pattern/: Each row to which the pattern can be matched;
            (3) Address range: #,# #,+#/pat1/,/pat2/#,/pat1/
            (4) ~: Step 1~2 2~2 Edit command: D: Delete P: Display content in mode space A \text: Append text after line, support using \ n to implement multiline append; I \text: Insert text before line, support use \ n to implement multiple-row inserts; C \text: Replace the behavior single or multiline text; w /path/to/somefile: Saves the mode space to match the row to the specified file; R/path/from/somefile: reads the text stream of the specified file to the row in the pattern space that matches to the row; =: Hit the line in the pattern space 
            Printing line number;!: take the opposite condition;
    s///: Supports the use of other delimiters, s@@@,s###; Replace tags: g: In-line global substitution;                P: Shows the row in which the replacement succeeds; W/path/to/somefile: Saves the result of the replacement success to the specified file; Exercise 1: Delete/boot/grub/g Rub.conf a white-space character in a file that starts with a blank line at the beginning of a white space; ~]# sed ' s@^[[:space:]]\+@@ '/etc/grub2.cfg Exercise 2: Delete/etc/f The # and whitespace characters in the stab file at the beginning of the line with #, followed by at least one white-space character; ~]# sed ' s@^#[[:space:]]\+@@ '/etc/fstab practice 3:e Cho an absolute path to the SED command, take out its base name; ~]# echo "/etc/sysconfig/" |
                Sed ' s@[^/]\+/\?$@@ ' advanced Edit command: H: The content of the mode space is covered to maintain space, H: the content of the pattern space is appended to the space of keeping;
                G: From the space to retain the data coverage to the mode space, G: from the retention of space to remove the content appended to the mode space; x: The content in the mode space is exchanged with the content in the space; N: Reads the next line to the pattern space of the line that matches to; N: appends the next line of the line to the pattern space; d: Deletes the rows in the mode space; D: Deletes all in the multiline mode space line; Sed-n ' N;p ' FILE: Show even-numbered sed ' 1! G;h;$!d ' file: Reverse display of file content sed ' $! n;$!
             D ' file: Two lines after the file is fetched; sed ' $!d ' file: Take out the last line of the file;   Sed ' G ' file:sed '/^$/d; G ' file:sed ' n;d ' FILE: show odd rows; Sed-n ' 1!
 G;h $p ' file: reverse displays each row in the file;

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.