The SED of the Linux op korimasa expression

Source: Internet
Author: User

One: The Linux op korimasa the sed of the expression

Sed: Stream editor, which is a unit of behavior

1. Options and Parameters:

-N: Use Quiet (silent) mode. In the usage of general sed, all data from STDIN is generally listed on the terminal. However, if you add the-n parameter, only the line (or action) that is specially processed by SED is listed.
-E: Action editing of SED directly in command-line mode;
-F: Write the action of SED directly in a file,
-I: Directly modifies the contents of the read file, not the output to the terminal.
A: New, a can be followed by a string, and these strings will appear in a new line
C: Replace, C can be followed by strings, these strings can replace the line between N1,N2!
D: Delete, because it is deleted ah, so d usually do not pick up any boom;
I: Insert, I can be followed by a string, and these strings will appear in a new line
P: Print, that is, print out a selected data.
S: Replace, can be replaced directly.

2. Example exercises:


[[Email protected] ~]# sed ' 3d ' test.txt <<<-----Delete third row

[[Email protected] ~]# sed ' 3p ' test.txt <<<-----Print Third line


[[Email protected] ~]# sed ' 1,4d ' a.txt <<<-----Delete line first to fourth
[Email protected] ~]#
[[Email protected] ~]# sed ' 1d,4d ' a.txt <<<-----Delete First and four rows

[[Email protected] ~]# sed '/sb.*$/d ' a.txt delete line ending with SB

[[Email protected] ~]# sed '/^s/c 1111 ' test.txt line with s beginning with 1111

[[Email protected] ~]# sed ' s/sb/sb/' a.txt to replace SB with SB
[[Email protected] ~]# sed ' s/sb/sb/g ' a.txt all replaced

[[email protected] ~]# sed-r '/^[0-9] ([a-z]+] xsb$/s/sb/sb/g ' a.txt

[[email protected] ~]# sed-r ' s/^ ([a-z]+] ([^a-z])/\2/g ' test.txt <<<------Delete the first word of each line
[[email protected] ~]# sed-r ' s/([^a-z]) ([a-z]+] $/\1/g ' test.txt <<<------Delete the last word per line

[[email protected] ~]# sed-r ' s/^ ([a-z]+) ([^a-z]+] ([a-z]+) ([^a-z]+]/\3\2\1\4/g ' test.txt ') first word and second word change position

[[email protected] ~]# sed-r ' s/^ (.) (. *) $/\2/' test.txt Delete the first character of each line of a file
[[email protected] ~]# sed-r ' s/^ (.) (.) (. *) $/\1\3/' test.txt Delete the second character of each line of a file
[[email protected] ~]# sed-r ' s/([^a-z]+) ([a-z]+] ([^a-z]) ([a-z]+]/\1\3\4/g ' test.txt
Delete the second-lowest word

[[email protected] ~]# Sed-ri ' s///g ' <<--+i change to file inside
Do not add I before the general write, see the output results are determined and then add I to save the changes.

The SED of the Linux op korimasa expression

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.