I am writing a bash script using awk with variable passing in AIX powerpc machine. The code written works fine after I read some questions & answers in this site. :)
Now, I'd like to add if statement in my bash script and I got awk syntax errors. My requirement (see my script below): - if awk pattern matching is true, print $0 - else print "transaction: p value not found."
Content of trans.txt
bash-4.2$ cat trans.txt
10291413
8537353
8619033
8619065
8625705
Could someone help me please. Thank you.
content of getDetail.sh
#!/usr/bin/bash
sysDir="/var/syslog-ng/TEST/STS"
syslogFile="DPSTSLog2014-10-22T09.log"
pattern="Latency"
filename=$1
while read f; do
concatPattern="$f.*$pattern"
awk -v p="$concatPattern" '$0 ~ p {print $0}' $sysDir/$syslogFile
done < $filename
run command execution below
./getDetails.sh trans.txt
result
2014-10-22T09:15:53+11:00,10.16.198.50,info,latency,[info] xmlfirewall(ws-TrustValidate): trans(10291413): Latency: 0 0 0 0 14 14 0 14 0 0 0 14 0 0 0 0
2014-10-22T09:15:38+11:00,10.16.198.50,info,latency,[info] xmlfirewall(ws-TrustValidate): trans(8619033): Latency: 0 0 0 0 73 73 0 73 0 0 0 73 0 0 0 0
2014-10-22T09:18:04+11:00,10.16.198.50,info,latency,[info] xmlfirewall(ws-TrustValidate): trans(8625705): Latency: 0 0 0 0 13 13 0 13 0 0 0 13 0 0 0 0
{print $0}could become{print $0;next} {do other thing}{print $0;next} {print "transaction: p value not found."}trans.txtand where is$filenameset?