Shell: Delete/Preserve a specified line in a file

Source: Internet
Author: User

Delete the first line in the file file1 to the line containing word characters and redirect to the file File2:

Sed ' 1,/word/d ' file1 > File2

Keep the lines in the file file1 that contain word characters and redirect to the file File2,-n to indicate that the results are not printed to the screen:

Sed-n '/word/p ' file1 > File2

Delete the contents of the >=21 line in the file file1, and-I means to save the changes directly in the FILE1:

Sed-i ', $d ' file1

Multiple conditions are separated by semicolons:

sed ' 1,/word1/d;21, $d;/word2/d ' file1 > File2

Shell: Delete/Preserve a specified line in a file

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.