LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   grep: Am I losing the plot? (https://www.linuxquestions.org/questions/linux-general-1/grep-am-i-losing-the-plot-4175679760/)

business_kid 08-01-2020 02:29 PM

grep: Am I losing the plot?
 
This is typical output from 'sudo iwlist wlan0 scan'

Code:

wlan0    Scan completed :
          Cell 01 - Address: 90:5C:44:AC:70:A6
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=50/70  Signal level=-60 dBm 
                    Encryption key:on
                    ESSID:"VM3BE77B4"

It's clear that each entry has a Channel entry, and a Quality. I've been checking things because I have a very slow wifi issue. Mow here's my problem - these checks were within a minute of each other
Code:

pi@raspberrypi:~ $ sudo iwlist wlan0 scan |grep -c Channel
14
pi@raspberrypi:~ $ sudo iwlist wlan0 scan |grep -c Quality
9
pi@raspberrypi:~ $ sudo iwlist wlan0 scan |grep -A2 Channel
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=48/70  Signal level=-62 dBm 
                    Encryption key:on
--
                    Channel:9
                    Frequency:2.452 GHz (Channel 9)
                    Quality=57/70  Signal level=-53 dBm 
                    Encryption key:on
--
                    Channel:9
                    Frequency:2.452 GHz (Channel 9)
                    Quality=58/70  Signal level=-52 dBm 
                    Encryption key:on
--
                    Channel:44
                    Frequency:5.22 GHz (Channel 44)
                    Quality=55/70  Signal level=-55 dBm 
                    Encryption key:on
--
                    Channel:1
                    Frequency:2.412 GHz (Channel 1)
                    Quality=68/70  Signal level=-42 dBm 
                    Encryption key:on
--
                    Channel:36
                    Frequency:5.18 GHz (Channel 36)
                    Quality=48/70  Signal level=-62 dBm 
                    Encryption key:on
--
                    Channel:6
                    Frequency:2.437 GHz (Channel 6)
                    Quality=47/70  Signal level=-63 dBm 
                    Encryption key:on
--
                    Channel:1
                    Frequency:2.412 GHz (Channel 1)
                    Quality=43/70  Signal level=-67 dBm 
                    Encryption key:on

grep is seeing 14 Channel results, only 9 Quality results, and only 8 results on Channel when I ask for the next 2 lines :confused: :banghead:

ondoho 08-01-2020 02:47 PM

That's not a good test for grep, that output changes all the time!
Why don't you test like this:
Code:

sudo iwlist wlan0 scan > text 2>&1
grep -c Channel text
...etc...


average_user 08-01-2020 05:16 PM

Quote:

Originally Posted by business_kid (Post 6151729)
and only 8 results on Channel when I ask for the next 2 lines :confused: :banghead:

x2 - notice that Channel occurs twice in each match.

business_kid 08-05-2020 02:05 PM

Got more sanity in the wifi output so this issue disappeared. Marking it solved.

BTW average user, the grep had 'Channel:n' & '(Cannel:n )' in it, and I don't thing the second one showed

average_user 08-05-2020 03:04 PM

I don't understand what you mean but you can make a test:
Code:

$ sudo iwlist wlan0 scan > /tmp/IWLIST_RESULT
$ grep -c Channel /tmp/IWLIST_RESULT
16
$ grep -A2 Channel /tmp/IWLIST_RESULT | grep -c Channel
16


business_kid 08-06-2020 04:05 AM

Yeah, here I got 34 & 34.But I went a bit further than your test, adding these lines
Code:

bash-5.0$ grep -A2 Channel /tmp/IWLIST_RESULT | grep -c (Channel
bash: syntax error near unexpected token `('
bash-5.0$ grep -A2 Channel /tmp/IWLIST_RESULT | grep -c \(Channel
17

So it appears the (Channel:n ) are being read and syntax errors ignored. That goes some was to explaining it.


All times are GMT -5. The time now is 12:16 PM.