LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   command for "strip out every line that doesn't contain xxxxx" (https://www.linuxquestions.org/questions/linux-general-1/command-for-strip-out-every-line-that-doesnt-contain-xxxxx-349064/)

Rotwang 08-01-2005 09:40 PM

command for "strip out every line that doesn't contain xxxxx"
 
Ok, so I'm stringing together some line commands here. Is there a line command that will do the following:

Given some newline seperated data (such as ls -l ) that's piped in ( with | ), do the following:

Remove every line that does NOT contain "abcdefg" on it. Or even better, could it remove every line that does not contain a regexp like /a*bcd(e|g)/;

Matir 08-01-2005 10:31 PM

Yes. It's called grep. :)

Specifically, it PRINTS every line that DOES contain the expression. Use 'egrep' for the more extended regexps, like above.

Shade 08-01-2005 10:36 PM

the -v option to grep will remove any line that contains the following exp. such as:

Code:

ls -l |grep -v whatever
Every line which does *not* include 'whatever' will be returned.

--Shade

Matir 08-01-2005 10:40 PM

I think the OP wanted to remove those that do NOT contain the expression. Which would be equivalent to printing those that DO contain the expression. Hence, no -v.

Shade 08-01-2005 10:42 PM

Wow. I think you're right. These double negatives confuse me :)

--Shade

Rotwang 08-02-2005 02:49 PM

Quote:

Originally posted by Matir
Yes. It's called grep. :)

Specifically, it PRINTS every line that DOES contain the expression. Use 'egrep' for the more extended regexps, like above.

Thanks. Duuh. I'm embarassed. (I think my double negatives confused me too.)

Matir 08-02-2005 03:08 PM

No problem. :) Don't be embarassed, I've asked plenty of obvious questions.


All times are GMT -5. The time now is 11:07 PM.