Daily shell exercise (--sed) processing

Source: Internet
Author: User
1. Exercises

For a file, 1 to 5 lines delete the line with English, 6 to 10 lines delete the English characters inside;

2. Analysis

This requirement, with the SED command can be solved, mainly used to match the knowledge of replacement.

3. Scripts
#!/bin/bashsed  -n ‘1,5p‘  a.txt  |  sed  ‘/[a-zA-Z]/d‘sed  -n ‘6,10p‘ a.txt  |  sed  ‘s/[a-zA-Z]//g‘sed  -n ‘11,$p‘ a.txt

The first two requirements, you must use line number matching. The primary sed is a stream-editing processor that receives input data one line at a line and then processes it.

The-N and-p options work together to output only matching content. So, in the first two lines the meaning of the command is equivalent, after matching to the corresponding line, only the rows are processed, and then through the pipeline, they passed to the following SED command processing.

The SED command in the third line is to output the screen directly from the text that is not processed. Thus, on the screen, it is equivalent to completely processing the entire text content.

Daily shell exercise (--sed) processing

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.