Linux Scripting Learn A

Source: Internet
Author: User
Tags first string modifier

    • Linux Scripting Learning


    • D: Delete rows that match the criteria

Sed ' 1,2d '/etc/fstab delete 1, 2 lines, show other rows


    • P: The line that displays the print fit condition

Sed '/^\//p '/etc/fstab matches the display, plus the original, there will be 2 duplicate

Sed-n '/^\//p/etc/fstab displays the line that matches the print


    • A: Add/string after the specified line

Sed '/^\//a \ #hello world '/etc/fstab \ #hello The world tested \# #都可以使用


    • I \string: Add a new line before the specified line


    • R file adds the contents of the specified file to the qualifying line

Sed ' 2r/etc/issue '/etc/fstab after the second line of the/etc/fstab file, add/etc/issue the entire file content


    • The W file saves the row in the range specified by the address to the specified file using the method as above R

Sed '/oot/w/tmp/oot.txt '/etc/fstab find oot lines in/etc/fstab file, save to/tmp/oot.txt inside


    • s/patten/string/modifier: Find and Replace, default to replace only the first time in each row by the pattern-matching string modifier

/patten/can use regular expressions

By default, the first string that is matched in each line

\ (\), \1 \2 can also be tried


    • Sed ' s#\ (L.. e\) #\1r#g ' Sed.txt

L.. E:liek-->liker

Love-->lover

&: Reference pattern matches entire string

Sed ' s#1..e#&r#g


    • G: Global Substitution

    • I: Ignore case

This article is from the "11498478" blog, please be sure to keep this source http://11508478.blog.51cto.com/11498478/1772804

Linux Scripting Learn A

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.