Ubuntu: How to script two informations with one command?



Question:

I'm trying to get more than one information in commandLine with iwlist commannd to get 'for example' Mac address and ESSID. I tried with

# iwlist wlan0 scan|egrep 'Address|ESSID'  

but I dont want all the lines but only the result 'for example'

# 00:13:33:83:36:F7  # Essid name  

there is any way to get that ? thanks.


Solution:1

Have you tried awk?

$> iwlist wlan0 scan | egrep 'Address|ESSID' | awk -F : '{ $1="";print}'    00 24 7E 1F 7B 4D    "YouShallNotPass!"  

With -F I changed the separator to colon : and alas took other colons from address, which can be remedied with setting OFS, like below:

$ iwlist wlan0 scan | grep Add | awk -F : '{OFS=":";$1="";print substr($0, 3) }'  00:24:7E:1F:7B:4D  

Looking at the results of 'iwlist ... scan' itself, they aren't always regular. I should mention two other lines you won't get this way:

  • Quality and Signal (no colon), use instead
    • iwlist wlan0 scan | grep Quality | awk '{print $3}' | awk -F = '{print $2}' for Signal
    • iwlist wlan0 scan | grep Quality | awk '{print $1}' | awk -F = '{print $2}' for Quality
  • Bit rates (well, in my case there are three lines with Bit rates, and one has no colon, just values - obviously the Awk script above misses it).

I'm not so familiar with what bit rates display exactly so not knowing your use case for this and whether this differs between many WiFi drivers/cards/others I lack info to help here.

Mind you - there are other options, but you withheld what you need and what for, so I gave you simple (if long) Awk-specific solution. Same info can be obtained via Perl regex or even Bash.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »