From :

sudo iwlist wlan0 scan | grep Frequency

I get

                Frequency:2.412 GHz (Channel 1)
                Frequency:2.412 GHz (Channel 1)
                Frequency:2.462 GHz (Channel 11)

But I want only output as

  • 1
    I'd strongly suggest taking a look at some regular expression tutorial first. You can then get what you want using grep -o, sed, or awk. – TooTea Jan 10 at 11:00

Add |awk -F 'Channel' '{print $2}' |cut -d ')' -f 1 to the command as this:

sudo iwlist wlan0 scan | grep Frequency |awk -F 'Channel' '{print $2}' |cut -d ')' -f 1

awk filter the world "Channel" while with the put you avoid the last ).

  • sudo iwlist wlan0 scan | sed -r -e 's/Frequency.*\(Channel ([0-9]+)\)$/\1/' – ctrl-alt-delor Jan 10 at 11:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.