1

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.

1
  • iwlist wlan0 scan|egrep 'Address|ESSID' | cut -d ":" -f 2- try this
    – devav2
    Nov 18, 2012 at 19:31

1 Answer 1

2

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.

2
  • So there is no way to take informations that I need exactly.
    – Ibrahim
    Nov 18, 2012 at 19:26
  • 2
    Ibrahim, is that a pressure-him-for-more attempt or are you just being melodramatic? ;-) I've added the Signal and Quality, but if you want a solution that serves your purpose... you should UNVEIL it. I consider the question "How to script two informations with one command" answered: you use pipes and Awk. Clearly you can get the EXACT result. If you need something more, do express this in your question please. Otherwise you are limiting the answer to just what you asked for, not what you need. Nov 18, 2012 at 20:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .