Register
It is currently Sun Nov 23, 2014 7:12 am

grep on WIFI output


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Sat Feb 08, 2014 7:09 pm   

Joined: Sat Feb 08, 2014 6:31 pm
Posts: 2
Hi everybody,

I'm playing with WIFI and I'm recording the output of iwlist in a file like that: (wlan0 is the name of my wireless interface)
Code:
iwlist wlan0 scanning > Output_Scan.txt


So now I'm trying to play a little bit with that file. And for example I would like to extract the ESSID names of my file. So I did the following code which running:
Code:
#!/bin/bash
Scan= "Output_Scan.txt"
echo "ESSID Names:"
while read Line
do echo $Line > tmp.txt
grep -i "ESSID" tmp.txt
done < $Scan
rm tmp.txt
exit 0


But I'm sure we can do something nicer! What are your suggestions?

And by the way why this command doesn't run?
Code:
(...) do grep -i "ESSID" $Line (...)


Finally does somebody know if we can search several strings at once with "grep" such as:
Code:
grep "wordA" OR "wordB"


Thanks in advance for any feedback,


Top
 Profile  
 PostPosted: Sun Feb 09, 2014 9:57 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 567
hi,

Code:
grep -iE "ESSID|Channel:|Quality" <(iwlist wlan0 scanning)
that's it.


Top
 Profile  
 PostPosted: Wed Feb 12, 2014 3:08 pm   

Joined: Sat Feb 08, 2014 6:31 pm
Posts: 2
Hi Watael,

Thanks for your feedback, and you're right it's more straight forward to use your command, but my goal was also to practice scripting and so I wrote the following code:

Code:
#!/bin/bash

# Script6.sh
# ESSID scan
echo
echo "Wireless scan in progress ..."
iwlist wlan0 scanning > ScanOutput.txt
echo "Scan done"
echo
echo "Network list :"
echo
file=ScanOutput.txt
while read Line
do
   echo $Line | grep -iE "ESSID|Channel:|Quality"
        [[ $(echo "$Line" | grep -c "Cell" ) -gt 0 ]] && echo
done < $file

echo
echo "Done"
echo

exit 0


Thanks again for your response,
All the best,


Top
 Profile  
 PostPosted: Wed Feb 12, 2014 4:29 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 567
Quote:
my goal was also to practice scripting
then avoid grep, and try to parse the output of the "wifi command" within a ``while'' loop, and avoid ``grep'' to use ``=~'' between ``[[ ]]''.
;)


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP