A brief discussion on several methods of simple elimination of strings under Linux (awk, sed, grep)

Source: Internet
Author: User

Study for a period of time, feeling in good condition, the teacher said the class can also be remembered, this is learned (note) the 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0071.gif "alt=" J_0071.gif "/>.

In the spirit of the beginning of his mercy, out of the Tao is very simple questions to test their own, not on the machine, handwriting ... It turned out to be tragic


Question 1: There are 3 lines of text that require the exclusion of intermediate lines, showing lines 1th and 3rd

Simulation Environment

[[email protected] tmp]# cat>>a.txt<<eof > aa> bb> cc> eof[[email protected] tmp]# cat A . txt aabbcc#eof can specify any character, try to use EOF, with other needs to avoid the same as the text content caused by unexpected end

idea 1: Eliminate text BB with awk inversion the wrong should not

[[email protected] tmp]# awk ' BB ' a.txt #不要让自己的行为, limiting their thinking [[email protected] tmp]# awk '!/bb/' a.txt aacc[[email protected] tmp]#


Idea 2: Eliminate the second line of text with the SED command

[[Email protected] tmp]# sed '/bb/d ' a.txt aacc# parameters and-n cannot be used at the same time, bastard the buttocks, provisions [[email protected] tmp]# sed-n '/bb/d ' a.txt [email Protected] tmp]#


Idea 3: Exclude text BB with the GREP-V parameter

[Email protected] tmp]# grep-v "BB" a.txt aacc[[email protected] tmp]#


This is basically the case, in the face of the problem, first put forward a solution, and then realize the method


Above his business not to be taken ... don't let the action limit your thoughts . Alas, the foundation is not strong, shake

This article is from the "Neon on the car Window" blog, please be sure to keep this source http://3524436.blog.51cto.com/3514436/1959371

A brief discussion on several methods of simple elimination of strings under Linux (awk, sed, grep)

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.