A usage of the SED command

Source: Internet
Author: User

The command is as follows:

1. Sed-n' 1 ~ 2! P'datafile

This command reads the datafile file to the mode space on each two lines, matches the first line in each two lines without printing, and prints the remaining lines to cancel the default output.

2. Sed-n' 1 ~ 2 P 'datafile

This command reads the datafile file to the mode space on each two lines, matches the first line in each two lines, prints the data, and does not print the remaining lines. The default output is canceled.

3. Sed '1 ~ 2d 'datafile

This command is equivalent to the first command.

Appendix: Explanations of SED command manual in Linux

First ~ Step
Match every step 'th line starting with line
First. For example, ''sed-N 1 ~ 2 P ''will print
All the odd-numbered lines in the input stream,
And the address 2 ~ 5 will match every th line,
Starting with the second. First can be zero; in
This case, sed operates as if it were equal
Step. (This is an extension .)


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.