bash - Output result of cli command to a file using awk to get columns -
i want record rssi @ point distance point router. distance user input , output file name user type like:
sh rssi.sh output.csv 20
where output.csv csv want append results , 20 distance
at moment rssi.sh looks like:
#!/bin/bash rssi_csv=$1 distance=$2 rssi=$(iwconfig wlan0 | awk -f'[ =]+' '/signal level/ {print $7}\') awk '{print $distance, $rssi}' > $rssi_csv
this creates rssi_csv per user input doesn't print required values in , i'm not sure why.
i imagine it's
awk '{print $distance, $rssi}' > $rssi_csv
that isn't working echo rssi or echo distance both output values screen. i'm using awk want have columns can output csv file, perhaps though there improve way?
there couple of issues awk
need pass variables using -v
alternative , utilize begin
block no input given. note single >
not append overwrite file. appending need >>
:
awk -vd=$distance -vr=$rssi 'begin{print d,r}' >> $rssi_csv
demo:
$ distance=20 $ rssi=$(iwconfig wlan0 | awk -f'[ =]+' '/signal level/ {print $7}') $ awk -vd=$distance -vr=$rssi 'begin{print d,r}' 20 -47
note: believe want comma separated values so:
$ awk -vd=$distance -vr=$rssi 'begin{print d","r}' 20,-47
however awk
overkill printing variables utilize old echo
:
$ echo "$distance,$rssi" 20,-47
bash awk sh
No comments:
Post a Comment