Thank all for your help, but nothing works...
The base command:
Code:
sudo iwlist wlan0 scan | grep ESSID | awk 'BEGIN {FS="\"";RS=" "}{print $2}'
The base script (doesn't work):
Code:
i=2
Scan=`sudo iwlist wlan0 scan | grep ESSID`
AwkCommand="awk 'BEGIN {FS=\"\\\"\";RS=\" \"}{print $"$i"}'"
$Scan | $AwkCommand
The error:
Code:
awk: 1: unexpected character '''
My objectives:
1. Save the list of all ESSID in $Scan ("Scan=`sudo iwlist wlan0 scan | grep ESSID`" works fine).
"echo $Scan" print this:
Code:
ESSID="Wireless"
ESSID="linksys"
ESSID="netgear"
ESSID="2345-1145"
2. With awk's command, I would like to keep only the ESSID's name ("Wireless", "linksys",...). I just did not understand the workings of awk. I thought it worked like that:
Code:
echo $Scan| awk 'BEGIN {FS="\"";RS=" "}{print $2}'
It gives me "Wireless"
Code:
echo $Scan| awk 'BEGIN {FS="\"";RS=" "}{print $4}'
It gives me "linksys"
Code:
echo $Scan| awk 'BEGIN {FS="\"";RS=" "}{print $6}'
It gives me "netgear"...
But no, I don't need to increment the $2 to $4,$6,$8...IThe command already give me all ESSID without the "ESSID=". Thus, I don't need to save the awk's argument.:-)
I have just to do that (maybe with the sed command I can separate ESSID):
Code:
Essid=`sudo iwlist wlan0 scan | grep ESSID`
echo $Essid | awk 'BEGIN {FS="\"";RS=" "}{print $2}'
Note: The essid's name are one below the other, I don't know why. But if you do this below, all essid's name are on a line separated by spaces:
Code:
$AllEssid=`echo $Essid | awk 'BEGIN {FS="\"";RS=" "}{print $2}'`
echo $AllEssid
But if you want to change the $2 to anything else, this one work great:
Code:
Essid=`sudo iwlist wlan0 scan | grep ESSID`
i="\$2"
echo $Essid | awk 'BEGIN {FS="\"";RS=" "}{print '$i'}'
I searched for anything...
But I don't know yet how to put a complete awk's command into a variable and then use it like a command...Problem with apostrophe I think. I'm curious if someone have an idea