Introduction to the SED command for Linux

Source: Internet
Author: User
Tags uuid

Sed:stream Editor, line editors:

Usage: sed [option] ... ' Script ' Inputfile ...

This shows the contents of the/etc/fstab, which will be used later

Common options:

    • -N: Do not output the contents of the mode to the screen
    • -e: Multi-point editing
    • -f:/path/to/script_file: Reading the edit script from the specified file
    • -R: Supports the use of extended regular expressions
    • -I: In situ editing

Address delimitation (Edit command bar below for an example):

    • Do not give address: the full text of the processing
    • Single Address:
      • #: The specified row
      • /pattern/: Each row to which the pattern can be matched
    • Address range:
      • #,#: First line to first line
      • #,+#: First few lines, a few lines
      • /pat1/,/pat2/: First occurrence of rows to/pat2/that meet/pat1/
      • #,/pat/: Which line is the first few lines

Edit command:

    • D: Delete. The following examples illustrate:
      • Delete line 6th, for example, clearly see line sixth disappears
      • Delete Line 1th to 3rd
      • Delete the beginning of the UUID line
      • Delete starts from the first line, altogether 5 lines

      • Delete from #/etc this line to the beginning of the UUID line

      • Delete the line from line 7th to the beginning of the UUID

    • P: Displays the contents of the mode space:
      • For example, show the line at the beginning of the UUID (this will output all the schema space content, and then one more row uuid)
      • If you want to output only what we want, use the-n

    • A \text: Append text after line, support multi-row append using \ n
    • For example, add Hello World after the/dev line, and all rows that meet the criteria are executed
    • I \text: inserting text in front of the line, enabling multi-row insertion using \ n (same as previous effect)
    • C \text: Replacing a line of behavior or multiple lines of text
    • W/path/to/somefile: Save the pattern space to match the line to the specified file
    • R/path/from/somefile: Reads the text of the specified file after the line that matches the line in the pattern space
    • =: Prints line numbers for lines in pattern space
    • ! : Take the reverse condition
    • s///: Supports the use of other separators, [email protected]@@,s###
      • Replace tag: g: inline global substitution. P: Displays the row where the replacement was successful.

Introduction to SED commands for Linux

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.