The SED syntax for Shell programming

Source: Internet
Author: User

First in the slot ads: want to go into a folder to see the following files must have permission to execute this file folder.

Sed

P prints the corresponding line 2p prints the second line.

-N outputs only rows processed by the SED command

Look at the Picture it is not very good at speech.

The second line is printed, but the others are printed.

At the same time, SED can also be placed behind the pipe symbol, see figure

d delete the specified line sed "1,2d" deletes 1, 2 rows from which you can see that line 12th is missing. But there is no real deletion of the contents of the original file. It was just deleted at the time of the output.

The-I operation also affects the original file Sed-i "1d" delete the first line and also delete the inside of the source file. (This is a good test)

A operation is added after this line.

The I action is added before this line.

Neither of these will affect the original file if you want to change the original file plus the-I operation.

C Operation SED "1c 999999" Cut1.txt first line replaced with 999999

s:s/old character/new character/g:sed s/xiaoq/xiaoq/g replace (no line number works on entire document)

You can also specify a line to replace 22 with Xiaoq

The SED syntax for Shell programming

Related Article

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.