PDA

View Full Version : [SOLVED] grep question



Peter76
December 22nd, 2007, 11:43 PM
Hell, I'm looking for a solution to the following problem:

I want to parse the output from
iwlist scan and print the lines with the essid and encryption info to the screen. I've tried :


iwlist scan | grep essid, enc

or another combination like that, but I can't get grep to take two arguments.... ANybody knows a solution to this?
Thanks in advance

Existentialist
December 22nd, 2007, 11:52 PM
You should be able to just pipe it in to grep again:

>iwlist scan | grep essid | grep enc

Peter76
December 22nd, 2007, 11:58 PM
@Existentialist: this does not work; you then pipe the output from the first grep to the second grep instead of the whole output....

Existentialist
December 23rd, 2007, 12:18 AM
@Existentialist: this does not work; you then pipe the output from the first grep to the second grep instead of the whole output....

Sorry misunderstood what you wanted. To search a list of patterns you use

>grep -E 'pattern1
>pattern2' file

The patterns need to be separated by a newline character like that. This should return any line containing one or both of the patterns.

geirha
December 23rd, 2007, 01:29 AM
Or you can use
iwlist scan | egrep 'ESSID|Encryption' It's case sensitive, so make sure to get that right too, or supply -i to the grep command to make it case insensitive.

Peter76
December 23rd, 2007, 10:42 AM
Thanks a lot for the last two solutions; work like a charm :-)