I'm pretty new to Shell Programming and I'm trying to write a script to display the out of a file displaying licence-use for an application. I've piped the output of my licence-use query to a file. On this file I am trying to run the following awk file, but I keep getting the error:
bash-3.00$ nawk -f ~/viewlicences.awk ~/licences
nawk: syntax error at source line 2
context is
if ($0 /Users of >>> SYNERGY-CMBase/) <<<
nawk: illegal statement at source line 2
This is my awk script that I'm trying to run on the file:
1 {
2 if ($0 [/Users of SYNERGY-CMBase/])
3 {
4 while ("x" == "x")
5 {
6 getline var
7 if (var == "") { continue }
8 if (var != /Users of SYNERGY-GroupSecurity/) { print var } else { exit }
9 }
10 }
11 }
I'm basically trying to capture output between the line which which says "Users of SYNERGY-CMBase" and Users of "SYNERGY-GroupSecurity".
No, I just put them in for the sake of readability. The line numbers themselves are largely irrelevant because depending on the number of licences in use, there may be more less entries in the file for each licence type.
Joeyg, many thanks for your help. Just before you had posted that, I changed my script to:
if ($0 ~ /Users of SYNERGY-CMBase:/) {print}
if ($0 ~ /"SYNERGY-CMBase"/)
{
while ("x" == "x")
{
getline var
if (var ~ /floating license/) {continue}
if (var == "") { continue }
if (var !~ /Users of SYNERGY-GroupSecurity/) {print var} else {exit}
}
}
}
which gives me the output:
Users of SYNERGY-CMBase: (Total of 12 licenses issued; Total of 3 licenses in use)
ccm_root phys-agsdev /dev/pts/67 u414014 (v1.0) (Phys-agsdev/19353 2477), start Mon 1/19 13:16
ccm_root phys-agsdev /dev/pts/19 z311203 (v1.0) (Phys-agsdev/19353 1449), start Mon 1/19 13:45
ccm_root phys-agsdev /dev/pts/104 u006134 (v1.0) (Phys-agsdev/19353 2017), start Mon 1/19 15:31
I'm now going to try and insert headers for username and process ID etc.