Related
I have csv file having below details, want to fetch the details based on time like
if hour is in betwwen 10 and 18 it should print be as morning, and rest of lines print night.
time,id
2022-08-01T00:09:14+09:00,PKA990
2022-08-01T06:48:24+09:00,PKA990
2022-08-01T08:27:23+09:00,
2022-08-01T11:04:18+09:00,ABCD890
2022-08-01T11:23:22+09:00,ABCD890
2022-08-01T11:30:14+09:00,
2022-08-01T12:01:12+09:00,ABCD890
2022-08-01T15:11:59+09:00,JIKOPL8
2022-08-01T18:20:53+09:00,TUVNDGD
im expecting output be like
time,id,session
2022-08-01T00:09:14+09:00,PKA990,night
2022-08-01T06:48:24+09:00,PKA990,night
2022-08-01T08:27:23+09:00,LOADING,night
2022-08-01T11:04:18+09:00,ABCD890,morning
2022-08-01T11:23:22+09:00,ABCD890,morning
2022-08-01T11:30:14+09:00,LOADING,morning
2022-08-01T12:01:12+09:00,ABCD890,morning
2022-08-01T15:11:59+09:00,JIKOPL8,morning
2022-08-01T18:20:53+09:00,TUVNDGD,night
Please suggest.
Sorry i haved edited some rows .... when ever there is an blank it should fill with "LOADING"
apologize
Here an awk solution:
#! /bin/bash
LC_ALL=en_US awk '
BEGIN {
FS=OFS=","
}
{
$1 = $1
}
NR == 1 {
print $0, "session", "day_of_week"
next
}
$2 == "" {
$2 = "LOADING"
}
{
date_timestamp=sprintf("%04d %02d %02d 00 00 00", substr($1, 1, 4), substr($1, 6, 2), substr($1, 9, 2))
day_of_week=tolower(strftime("%A", mktime(date_timestamp)))
if ($1 ~ /^[-0-9]+T(10|11|12|13|14|15|16|17):/) {
session="morning"
} else {
session="night"
}
}
{
print $0, session, day_of_week
}
' <"datetime.csv"
Output:
time,id,session,day_of_week
2022-08-01T00:09:14+09:00,PKA990,night,monday
2022-08-01T06:48:24+09:00,PKA990,night,monday
2022-08-01T08:27:23+09:00,LOADING,night,monday
2022-08-01T11:04:18+09:00,ABCD890,morning,monday
2022-08-01T11:23:22+09:00,ABCD890,morning,monday
2022-08-01T11:30:14+09:00,LOADING,morning,monday
2022-08-01T12:01:12+09:00,ABCD890,morning,monday
2022-08-01T15:11:59+09:00,JIKOPL8,morning,monday
2022-08-01T18:20:53+09:00,TUVNDGD,night,monday
A pure bash solution:
#! /bin/bash
INPUT_FILENAME="datetime.csv"
FLAG_FIRST=1
FS=","
OFS=","
while read -r LINE; do
if [[ ${FLAG_FIRST} -eq 1 ]]; then
printf "%s%s%s%s%s\n" "${LINE//${FS}/${OFS}}" "${OFS}" "session" "${OFS}" "day_of_week"
FLAG_FIRST=0
continue
fi
# Ignore empty lines
[[ -z "${LINE}" ]] && continue
# If LINE ends with coma (assume id field is empty):
# put "LOADING" token at end of line
[[ "${LINE}" =~ ${FS}$ ]] && LINE+="LOADING"
# LC_ALL=en_US to obtains day of week in english (I'am french)
# Use ${LINE%%T*} to use date field without hour and timezone
DAY_OF_WEEK=$(LC_ALL=en_US date +%A --date "${LINE%%T*}")
# In english, day of week begins with an uppercase letter:
# use a coma after variable name to put it in lowercase
if [[ "${LINE}" =~ ^[-0-9]+T(10|11|12|13|14|15|16|17): ]]; then
SESSION="morning"
else
SESSION="night"
fi
printf "%s%s%s%s%s\n" "${LINE//${FS}/${OFS}}" "${OFS}" "${SESSION}" "${OFS}" "${DAY_OF_WEEK,}"
done < <(cat "${INPUT_FILENAME}"; echo)
Output:
time,id,session,day_of_week
2022-08-01T00:09:14+09:00,PKA990,night,monday
2022-08-01T06:48:24+09:00,PKA990,night,monday
2022-08-01T08:27:23+09:00,LOADING,night,monday
2022-08-01T11:04:18+09:00,ABCD890,morning,monday
2022-08-01T11:23:22+09:00,ABCD890,morning,monday
2022-08-01T11:30:14+09:00,LOADING,morning,monday
2022-08-01T12:01:12+09:00,ABCD890,morning,monday
2022-08-01T15:11:59+09:00,JIKOPL8,morning,monday
2022-08-01T18:20:53+09:00,TUVNDGD,night,monday
This question already has answers here:
How to wrap lines within columns in Linux
(2 answers)
Closed 3 years ago.
I am trying to wrap columns of text using gawk or native bash, The fourth column (last one in this case) wraps to the next line. I would like it to wrap and all text remain under the respective heading. The output for the given input is just representative and text needing wrapped is in the last column. However id like to wrap ANY column
I have tried embedding fmt and fold commands in the awk script but have been unsuccessful in getting results required.
awk 'BEGIN{FS="|"; format="%-35s %-7s %-5s %-20s\n"
printf "\n"
printf format, "Date", "Task ID", "Code", "Description"
printf format ,"-------------------------", "-------", "-----", "------------------------------"}
{printf format, strftime("%c",$1), $2, $3, $4}'
INPUT:
1563685965|878|12015|Task HMI starting
1563686011|881|5041|Configured with engine 6000.8403 (/opt/NAI/LinuxShield/engine/lib/liblnxfv.so), dats 9322.0000 (/opt/NAI/LinuxShield/engine/dat), 197 extensions, 0 extra drivers
1563686011|882|5059|Created Scanner child id=1 pid=28,698 engine=6000.8403, dats=9322.0000
1563686139|883|12017|Task HMI Completed 2 items detected in 19 files (0 files timed out, 0 files excluded, 0 files cleaned, 0 files had errors, 0 were not scanned)
1563686139|885|5012|scanned=19 excluded=0 infected=2 cleaned=0 cleanAttempts=0 cleanRequests=0 denied=0 repaired=0 deleted=0 renamed=0 quarantined=0 timeouts=0 errors=0 uptime=174 busy=0 wait=0
I am still unclear on how to post or share on formation on this forum. This seems to work fairly well. The wrap function was taken from the duplicate post.
BEGIN{
format="%-35s %-7s %-10s %-20s\n"
printf "\n"
printf format, "Date", "Task ID", "Code", "Description"
printf format ,"-------------------------", "-------", "-----", "------------------------------"
}
{
split($0,cols,"|")
numLines=1
for(col in cols){
numLines=wrap(cols[col],80,colArr)
for(c in colArr){
fmtcol[col,c] = colArr[c]
}
maxLinesRow[col]=(numLines > maxLinesRow[col] ? numLines : maxLinesRow[col])
}
for (lineNr=1; lineNr<=maxLinesRow[col]; lineNr++) {
dt=((1,lineNr) in fmtcol ? strftime("%c",fmtcol[1,lineNr]):"")
printf format, dt, fmtcol[2,lineNr], fmtcol[3,lineNr], fmtcol[4,lineNr]
}
printf "\n"
delete colArr
}
function wrap(inStr,wid,outArr, lineEnd,numLines) {
while ( length(inStr) > wid ) {
lineEnd = ( match(substr(inStr,1,wid),/.*[[:space:]]/) ? RLENGTH - 1 : wid )
outArr[++numLines] = substr(inStr,1,lineEnd)
inStr = substr(inStr,lineEnd+1)
sub(/^[[:space:]]+/,"",inStr)
}
outArr[++numLines] = inStr
return numLines
}
I know you said you're using gawk, but tabular formatting with line wrapping like you want is really easy to do with perl, so here's a perl solution using the format feature's repeated fill mode:
#!/usr/bin/env perl
use warnings;
use strict;
use POSIX qw/strftime/;
printf "%-40s %-20s\n", 'Date', 'Description';
print '-' x 40, ' ', '-' x 20, "\n";
my ($date, $desc);
while (<>) {
chomp;
($date, $desc) = split '\|', $_;
$date = strftime '%c', localtime($date);
write;
}
format STDOUT =
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ^<<<<<<<<<<<<<<<<<<< ~~
$date, $desc
.
Example:
$ cat input.txt
1000|this is some text
2000|this is some other text that is long enough that it will wrap around a bit.
$ perl fmt.pl input.txt
Date Description
---------------------------------------- --------------------
Wed, Dec 31, 1969 4:16:40 PM this is some text
Wed, Dec 31, 1969 4:33:20 PM this is some other
text that is long
enough that it will
wrap around a bit.
A server provides a list of asset IDs separated by commas in square brackets after the date and colons :
20160420084726:-
20160420085418:[111783178, 111557953, 111646835, 111413356, 111412662, 105618372, 111413557]
20160420085418:[111413432, 111633904, 111783198, 111792767, 111557948, 111413225, 111413281]
20160420085418:[111413432, 111633904, 111783198, 111792767, 111557948, 111413225, 111413281]
20160420085522:[111344871, 111394583, 111295547, 111379566, 111352520]
20160420090022:[111344871, 111394583, 111295547, 111379566, 111352520]
The format of the input log is:
timestamp:ads
Where:
timestamp is in the format YYYYMMDDhhmmss, and ads is a comma separated list of ad asset IDs surrounded by square brackets, or - if no ads were returned.
The first part of the task is to write a script that outputs, for each ten minute slice of the day:
Count of IDs that were returned
Count of unique IDs that were returned
Script should support a command line parameter to select whether unique or total IDs should be given.
Example output using the above log excerpt (in total mode):
20160420084:0
20160420085:26
20160420090:5
And in unique count mode it would give:
20160420084:0
20160420085:19
20160420090:5
I have tried this:
awk -F '[,:]' '
{
key = substr($1,1,11)"0"
count[key] += ($2 == "-" ? 0 : NF-1)
}
END {
PROCINFO["sorted_in"] = "#ind_num_asc"
for (key in count) print key, count[key]
}
' $LOGFILENAME | grep $DATE;
With the scripts given until now other scenarios fail. For example this one:
log file:
https://drive.google.com/file/d/1sXFvLyCH8gZrXiqf095MubyP7-sLVUXt/view?usp=sharing
The first few lines of the results should be:
nonunique:
20160420000:1
20160420001:11
20160420002:13
20160420003:16
20160420004:3
20160420005:3
20160420010:6
unique:
20160420000:1
20160420001:5
20160420002:5
20160420003:5
20160420004:3
20160420005:3
20160420010:4
$ cat tst.awk
BEGIN { FS="[]:[]+"; OFS=":" }
{
tot = unq = 0
time = substr($1,1,11)
if ( /,/ ) {
tot = split($2,tmp,/, ?/)
for ( i in tmp ) {
if ( !seen[time,tmp[i]]++ ) {
unq++
}
}
}
tots[time] += tot
unqs[time] += unq
}
END {
for (time in tots) {
print time, tots[time], unqs[time]
}
}
$ awk -f tst.awk file
20160420084:0:0
20160420085:26:19
20160420090:5:5
Massage to suit...
#!/bin/bash
while read; do
dts=$( echo "$REPLY" | cut -d: -f1 )
ids=$( echo "$REPLY" | grep -o '\[.*\]' )
if [ $? -eq 0 ]; then
ids=$( echo "$ids" | tr -d '[] ' | tr ',' '\n' | sort $1 )
count=$( echo "$ids" | wc -l )
else
count=0
fi
echo $dts: $count
done
Run like this:
./script.sh [-u] <input.txt
I have a protein sequence file in the following format
uniprotID\space\sequence
sequence is a string of any length but with only 20 allowed letters i.e.
ARNDCQEGHILKMFPSTWYV
Example of 1 record
Q5768D AKCCACAKCCAC
I want to create a csv file in the following format
Q5768D
12
ACA 1
AKC 2
CAC 2
CAK 1
CCA 2
KCC 2
This is what I'm currently trying:
#!/bin/sh
while read ID SEQ # uniprot along with sequences
do
echo $SEQ | tr -d '[[:space:]]' | sed 's/./& /g' > TEST_FILE
declare -a SSA=(`cat TEST_FILE`)
SQL=$(echo ${#SSA[#]})
for (( X=0; X <= "$SQL"; X++ ))
do
Y=$(expr $X + 1)
Z=$(expr $X + 2)
echo ${SSA[X]} ${SSA[Y]} ${SSA[Z]}
done | awk '{if (NF == 3) print}' | tr -d ' ' > TEMPTRIMER
rm TEST_FILE # removing temporary sequence file
sort TEMPTRIMER|uniq -c > $ID.$SQL
done < $1
in this code i am storing individual record in a different file which is not good. Also the program is very slow in 12 hours only 12000 records are accessed out of .5 million records.
If this is what you want:
$ cat file
Q5768D AKCCACAKCCAC
OTHER FOOBARFOOBAR
$
$ awk -f tst.awk file
Q5768D OTHER
12 12
AKC 2 FOO 2
KCC 2 OOB 2
CCA 2 OBA 2
CAC 2 BAR 2
ACA 1 ARF 1
CAK 1 RFO 1
This will do it:
$ cat tst.awk
BEGIN { OFS="\t" }
{
colNr = NR
rowNr = 0
name[colNr] = $1
lgth[colNr] = length($2)
delete name2nr
for (i=1;i<=(length($2)-2);i++) {
trimer = substr($2,i,3)
if ( !(trimer in name2nr) ) {
name2nr[trimer] = ++rowNr
nr2name[colNr,rowNr] = trimer
}
cnt[colNr,name2nr[trimer]]++
}
numCols = colNr
numRows = (rowNr > numRows ? rowNr : numRows)
}
END {
for (colNr=1;colNr<=numCols;colNr++) {
printf "%s%s", name[colNr], (colNr<numCols?OFS:ORS)
}
for (colNr=1;colNr<=numCols;colNr++) {
printf "%s%s", lgth[colNr], (colNr<numCols?OFS:ORS)
}
for (rowNr=1;rowNr<=numRows;rowNr++) {
for (colNr=1;colNr<=numCols;colNr++) {
printf "%s %s%s", nr2name[colNr,rowNr], cnt[colNr,rowNr], (colNr<numCols?OFS:ORS)
}
}
}
If instead you want output like in #rogerovo's perl answer that'd be much simpler than the above and more efficient and use far less memory:
$ cat tst2.awk
{
delete cnt
for (i=1;i<=(length($2)-2);i++) {
cnt[substr($2,i,3)]++
}
printf "%s;%s", $1, length($2)
for (trimer in cnt) {
printf ";%s=%s", trimer, cnt[trimer]
}
print ""
}
$ awk -f tst2.awk file
Q5768D;12;ACA=1;KCC=2;CAK=1;CAC=2;CCA=2;AKC=2
OTHER;12;RFO=1;FOO=2;OBA=2;OOB=2;ARF=1;BAR=2
This perl script processes cca 550'000 "trimmers"/sec. (random valid test sequences 0-8000 chars long, 100k records (~400MB) produce an 2GB output csv)
output:
Q1024A;421;AAF=1;AAK=1;AFC=1;AFE=2;AGP=1;AHC=1;AHE=1;AIV=1;AKN=1;AMC=1;AQD=1;AQY=1;...
Q1074F;6753;AAA=1;AAD=1;AAE=1;AAF=2;AAN=2;AAP=2;AAT=1;ACA=1;ACC=1;ACD=1;ACE=3;ACF=2;...
code:
#!/usr/bin/perl
use strict;
$|=1;
my $c;
# process each line on input
while (readline STDIN) {
$c++; chomp;
# is it a valid line? has the format and a sequence to process
if (m~^(\w+)\s+([ARNDCQEGHILKMFPSTWYV]+)\r?$~ and $2) {
print join ";",($1,length($2));
my %trimdb;
my $seq=$2;
#split the sequence into chars
my #a=split //,$seq;
my #trimmer;
# while there are unprocessed chars in the sequence...
while (scalar #a) {
# fill up the buffer with a char from the top of the sequence
push #trimmer, shift #a;
# if the buffer is full (has 3 chars), increase the trimer frequency
if (scalar #trimmer == 3 ) {
$trimdb{(join "",#trimmer)}++;
# drop the first letter from buffer, for next loop
shift #trimmer;
}
}
# we're done with the sequence - print the sorted list of trimers
foreach (sort keys %trimdb) {
#print in a csv (;) line
print ";$_=$trimdb{$_}";
}
print"\n";
}
else {
#the input line was not valid.
print STDERR "input error: $_\n";
}
# just a progress counter
printf STDERR "%8i\r",$c if not $c%100;
}
print STDERR "\n";
if you have perl installed (most linuxes do, check the path /usr/bin/perl or replace with yours), just run: ./count_trimers.pl < your_input_file.txt > output.csv
I wrote wlan manager script to handle open/ad-hoc/wep/wpa2 networks. Now im trying to parse iw wlan0 scan output to get nice scan feature to my script. My goal is to get output like this :
SSID channel signal encryption
wlan-ap 6 70% wpa2-psk
test 1 55% wep
What i have achived already is output like this :
$ iw wlan0 scan | grep 'SSID\|freq\|signal\|capability' | tac
SSID: Koti783
signal: -82.00 dBm
capability: ESS Privacy ShortPreamble SpectrumMgmt ShortSlotTime (0x0531)
freq: 2437
I have been trying to study bash/sed/awk but havent found yet a way to achieve what im trying. So what is good way to achieve that?
Here is my final solution based of Sudo_O answer:
$1 == "BSS" {
MAC = $2
wifi[MAC]["enc"] = "Open"
}
$1 == "SSID:" {
wifi[MAC]["SSID"] = $2
}
$1 == "freq:" {
wifi[MAC]["freq"] = $NF
}
$1 == "signal:" {
wifi[MAC]["sig"] = $2 " " $3
}
$1 == "WPA:" {
wifi[MAC]["enc"] = "WPA"
}
$1 == "WEP:" {
wifi[MAC]["enc"] = "WEP"
}
END {
printf "%s\t\t%s\t%s\t\t%s\n","SSID","Frequency","Signal","Encryption"
for (w in wifi) {
printf "%s\t\t%s\t\t%s\t%s\n",wifi[w]["SSID"],wifi[w]["freq"],wifi[w]["sig"],wifi[w]["enc"]
}
}'
Output:
$ sudo iw wlan0 scan | awk -f scan.awk
SSID Frequency Signal Encryption
netti 2437 -31.00 dBm Open
Koti783 2437 -84.00 dBm WPA
WLAN-AP 2462 -85.00 dBm WPA
it's generally bad practice to try parsing complex output of programs intended for humans to read (rather than machines to parse).
e.g. the output of iw might change depending on the language settings of the system and/or the version of iw, leaving you with a "manager" that only works on your development machine.
instead you might use the same interface that iw uses to get it's information: the library backend libnl
you might also want to have a look at the wireless-tools (iwconfig, iwlist,...) that use the libiw library.
Here is an GNU awk script to get you going that grabs the SSIDs and the channel for each unique BSS:
/^BSS / {
MAC = $2
}
/SSID/ {
wifi[MAC]["SSID"] = $2
}
/primary channel/ {
wifi[MAC]["channel"] = $NF
}
# Insert new block here
END {
printf "%s\t\t%s\n","SSID","channel"
for (w in wifi) {
printf "%s\t\t%s\n",wifi[w]["SSID"],wifi[w]["channel"]
}
}
It should be easy for you to add the new blocks for signal and encryption considering all the studying you have been doing.
Save the script to file such as wifi.awk and run like:
$ sudo iw wlan0 scan | awk -f wifi.awk
The output will be in the formatted requested:
SSID channel
wlan-ap 6
test 1
Here is a simple Bash function which uses exclusively Bash internals and spawns only one sub-shell:
#!/bin/bash
function iwScan() {
# disable globbing to avoid surprises
set -o noglob
# make temporary variables local to our function
local AP S
# read stdin of the function into AP variable
while read -r AP; do
## print lines only containing needed fields
[[ "${AP//'SSID: '*}" == '' ]] && printf '%b' "${AP/'SSID: '}\n"
[[ "${AP//'signal: '*}" == '' ]] && ( S=( ${AP/'signal: '} ); printf '%b' "${S[0]},";)
done
set +o noglob
}
iwScan <<< "$(iw wlan0 scan)"
Output:
-66.00,FRITZ!Box 7312
-56.00,ALICE-WLAN01
-78.00,o2-WLAN93
-78.00,EasyBox-7A2302
-62.00,dlink
-74.00,EasyBox-59DF56
-76.00,BELAYS_Network
-82.00,o2-WLAN20
-82.00,BPPvM
The function can be easily modified to provide additional fields by adding a necessary filter into the while read -r AP while-loop, eg:
[[ "${AP//'last seen: '*}" == '' ]] && ( S=( ${AP/'last seen: '} ); printf '%b' "${S[0]},";)
Output:
-64.00,1000,FRITZ!Box 7312
-54.00,492,ALICE-WLAN01
-76.00,2588,o2-WLAN93
-78.00,652,LN8-Gast
-72.00,2916,WHITE-BOX
-66.00,288,ALICE-WLAN
-78.00,800,EasyBox-59DF56
-80.00,720,EasyBox-7A2302
-84.00,596,ALICE-WLAN08
I am using such solution for openwrt:
wlan_scan.sh
#!/bin/sh
sudo iw dev wlan0 scan | awk -f wlan_scan.awk | sort
wlan_scan.awk
/^BSS/ {
mac = gensub ( /^BSS[[:space:]]*([0-9a-fA-F:]+).*?$/, "\\1", "g", $0 );
}
/^[[:space:]]*signal:/ {
signal = gensub ( /^[[:space:]]*signal:[[:space:]]*(\-?[0-9.]+).*?$/, "\\1", "g", $0 );
}
/^[[:space:]]*SSID:/ {
ssid = gensub ( /^[[:space:]]*SSID:[[:space:]]*([^\n]*).*?$/, "\\1", "g", $0 );
printf ( "%s %s %s\n", signal, mac, ssid );
}
result
-62.00 c8:64:c7:54:d9:05 a
-72.00 70:72:3c:1c:af:17 b
-81.00 78:f5:fd:be:33:cb c
There is a bug in the awk script above.
The following code will not work if the SSID has spaces in the name. The received result will be the first token of the SSID name only.
$1 == "SSID:" {
wifi[MAC]["SSID"] = $2
}
When printing $0, $1, $2:
$0: SSID: DIRECT-82-HP OfficeJet 8700
$1: SSID:
$2: DIRECT-82-HP
One possibly solution is to take a substr of $0 which contains leading spaces, the token "SSID: " and the provided multi-token network name.
Any other suggestions?
I've taken awk code from Ari Malinen and reworked it a bit, because iw output is not stable and changes, also there are other issues like spaces in SSID. I put it on github in case if I'll change it in the future.
#!/usr/bin/env awk -f
$1 ~ /^BSS/ {
if($2 !~ /Load:/) { #< Escape "BBS Load:" line
gsub("(\\(.*|:)", "", $2)
MAC = toupper($2)
wifi[MAC]["enc"] = "OPEN"
wifi[MAC]["WPS"] = "no"
wifi[MAC]["wpa1"] = ""
wifi[MAC]["wpa2"] = ""
wifi[MAC]["wep"] = ""
}
}
$1 == "SSID:" {
# Workaround spaces in SSID
FS=":" #< Changing field separator on ":", it should be
# forbidded sign for SSID name
$0=$0
sub(" ", "", $2) #< remove first whitespace
wifi[MAC]["SSID"] = $2
FS=" "
$0=$0
}
$1 == "capability:" {
for(i=2; i<=NF; i++) {
if($i ~ /0x[0-9]{4}/) {
gsub("(\\(|\\))", "", $i)
if (and(strtonum($i), 0x10))
wifi[MAC]["wep"] = "WEP"
}
}
}
$1 == "WPA:" {
wifi[MAC]["wpa1"] = "WPA1"
}
$1 == "RSN:" {
wifi[MAC]["wpa2"] = "WPA2"
}
$1 == "WPS:" {
wifi[MAC]["WPS"] = "yes"
}
$1 == "DS" {
wifi[MAC]["Ch"] = $5
}
$1 == "signal:" {
match($2, /-([0-9]{2})\.00/, m)
wifi[MAC]["Sig"] = m[1]
}
$1 == "TSF:" {
gsub("(\\(|d|,)", "", $4)
match($5, /([0-9]{2}):([0-9]{2}):/, m)
day = $4
hour = m[1]
min = m[2]
wifi[MAC]["TSF"] = day"d"hour"h"min"m"
}
END {
for (w in wifi) {
if (wifi[w]["wep"]) {
if (wifi[w]["wpa1"] || wifi[w]["wpa2"])
wifi[w]["enc"] = wifi[w]["wpa1"]wifi[w]["wpa2"]
else
wifi[w]["enc"] = "WEP"
}
printf "%s:%s:%s:%s:%s:%s:%s\n", w, wifi[w]["SSID"], wifi[w]["enc"], \
wifi[w]["WPS"], wifi[w]["Ch"], wifi[w]["Sig"], wifi[w]["TSF"]
}
}
Output:
A5FEF2C499BB:test-ssid2:OPEN:no:9:43:0d00h00m
039EFACA9A8B:test-ssid2:WPA1:no:9:33:0d00h00m
038BF3C1988B:test-ssid2:WPA2:no:9:35:0d00h00m
028EF3C2997B:test-ssid2:WPA1:no:9:35:0d00h03m
if you wonder what if($2 !~ /Load:/) does, well on some routers there might be "BSS Load:" string.