I'm trying to run the command
iwlist scan, remove the errors and process the output to my own specification by using
grep &
sed to find and pick specific lines, from a text file, over a
for loop and then store some of the information as a variable for future use as I develop the code
my code looks like this at the moment
Code:
#!/bin/bash
# counts number of cells found, i.e. number of broacasting routers in range
varA=`iwlist scan 2>/dev/null | egrep -c "Cell"`
#saves the output minus errors
iwlist scan 2>/dev/null | egrep "Address" > ~/Desktop/coutput1
# my for loop where i try to set var(1,2,3 etc) to the output in coutput1
for i in $(eval echo {1..$varA})
do
var$i=`sed -n "$i"p "~/Desktop/coutput1" | cut -c 30-47`
done
# print var's
echo $varA
echo $var$1
I try to cut the output below and for example save
var1 as the address for cell 01
where coutput1 looks like this:
Code:
Cell 01 - Address: AA:BB:CC:DD:EE:FF
Cell 02 - Address: AA:BB:CC:DD:EE:FF
Cell 03 - Address: AA:BB:CC:DD:EE:FF
the line
Code:
var$i=`sed -n "$i"p "~/Desktop/coutput1" | cut -c 30-47`
just doesn't seem to want to work and i don't know where to go. Maybe there's other problems with the rest of the code?
I appreciate that this code is inefficient but most of it was for my own learning and compiled from multiple online guides etc