Re: Bash script for wireless
Hi John,
> I know how to use grep etc. to find known bits of output, but not
> how to isolate arbitrary output, for example ESSID names.
>
> Can anyone point me in the right direction?
I used this in one script of mine:
available_essids=`iwlist air0 scanning | grep "ESSID" | sed 's/.*"\(.*\)".*/\1/'`
As so often, sed is write-once-read-never, so I will try to explain;-)
After the grep the input to sed should look something like this:
<output of grep>
ESSID:"FOO"
ESSID:"BAR"
ESSID:"BAZ"
</output of grep>
sed will now extract the string inside the quotes:
<part1 '.*"> ESSID:"</part1><grouped part1 '\(.*\)'>FOO</grouped part1><ungrouped part2 '".*'>"</ungrouped part2>
etc.
Well, maybe this is even more obfuscated, but at least I tried..
Cheers,
Johannes
Reply to: