Basic usage of SED

Source: Internet
Author: User

SED basic usage:
Sed:stream Editor Editor is in line editor (vi is Full screen editor)


SED: Mode space
Edit the original file by default, processing only the data in the pattern space

sed [options] ' Addresscommand ' FILE ...


Options
-N: Silent mode, no longer displays the contents of the mode space by default
                -I: Modify the original file directly
                -E script-e script: Multiple scripts can be executed at the same time
                -F ScriptFile: Specifies the file where the script is stored
Sed-f/path/of/scripts FILE
                -r: Indicates the use of extended regular expressions

Address:
1. startingline,endling with line numbers
1,100--From line 1th to line 100
                        $: Last line
                2./regexp/---using regular expressions
/^root/---lines starting with Root

                3./pattern1,pattern2/---from the first line that was matched by PATTERN1, to the end of the line that was first matched to the pattern2, all the rows in the middle

                4. LineNumber---The specified row

                5. StartLine, +n---starting from StartLine, N rows Backward, total n+1 rows

    Command
D: Delete rows that match the criteria
                P: Show rows that match the criteria
                A \ "string": Appends a new line after the specified line with the contents "string"
                I \string: Appends a new line to the specified line, with the contents "string"
                R file: Adds the contents of the specified file to the qualifying line
                W file: Saves the contents of the specified row to the specified file
                s/pattern/string/: Find and Replace, default replaces only the first string in each row that is matched by the pattern
G: Global Substitution
                        I: Find is ignore character case

                Note: s///<---> s### <---> [email protected]@@, separators can be represented using the same three symbols
\ (\), \1, \2
                        &: The string to which the reference pattern matches

Basic usage of SED

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.