LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-01-2020, 02:29 PM   #1
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 11,669

Rep: Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362
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
 
Old 08-01-2020, 02:47 PM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 14,976
Blog Entries: 9

Rep: Reputation: 4240Reputation: 4240Reputation: 4240Reputation: 4240Reputation: 4240Reputation: 4240Reputation: 4240Reputation: 4240Reputation: 4240Reputation: 4240Reputation: 4240
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...

Last edited by ondoho; 08-02-2020 at 02:38 AM.
 
Old 08-01-2020, 05:16 PM   #3
average_user
Member
 
Registered: Dec 2010
Location: Warsaw, Poland
Distribution: Slackware
Posts: 516

Rep: Reputation: 205Reputation: 205Reputation: 205
Quote:
Originally Posted by business_kid View Post
and only 8 results on Channel when I ask for the next 2 lines
x2 - notice that Channel occurs twice in each match.
 
Old 08-05-2020, 02:05 PM   #4
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 11,669

Original Poster
Rep: Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362
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
 
Old 08-05-2020, 03:04 PM   #5
average_user
Member
 
Registered: Dec 2010
Location: Warsaw, Poland
Distribution: Slackware
Posts: 516

Rep: Reputation: 205Reputation: 205Reputation: 205
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

Last edited by average_user; 08-05-2020 at 03:26 PM.
 
Old 08-06-2020, 04:05 AM   #6
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware & Android
Posts: 11,669

Original Poster
Rep: Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362Reputation: 1362
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an alias in ksh that uses grep and includes 'grep -v grep' doug248 Linux - Newbie 2 08-05-2012 02:07 PM
losing DSL, losing GRUB controller andreas_skw Linux - Newbie 4 06-14-2008 01:36 AM
losing DSL, losing GRUB controller andreas_skw Linux - Newbie 1 06-10-2008 11:46 AM
setting up mail server...losing the plot retarded Linux - Newbie 7 12-02-2003 02:05 AM
Real Time Plot... DaFrEQ Linux - Software 0 08-27-2002 08:25 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration