I'm trying to capture the value of "License Name", "User", "Total Number of Licenses", "Number of licenses used", "Expiry Date", "License Checkout Date", "Server name" on the below output:
Users of avy_amba_portfolio: (Total of 21 licenses issued; Total of 5 licenses in use)
"avy_amba_portfolio" v1.5, vendor: AVERYDES, expiry: 30-apr-2024
user1 server1 /dev/pts/5 (v0.20220708) (license_server_1/1234 3402), start Tue 3/5 22:22
user1 server6 /dev/pts/22 (v0.20220708) (license_server_1/1234 488), start Wed 3/6 1:19
user1 server1 /dev/pts/80 (v0.20220708) (license_server_1/1234 3554), start Wed 3/6 23:55
user1 server1 /dev/pts/83 (v0.20220708) (license_server_1/1234 5850), start Thu 3/7 0:03
user2 server1 /dev/pts/47 (v0.20220920) (license_server_1/1234 1713), start Thu 3/7 3:10
Users of avy_jtag: (Total of 6 licenses issued; Total of 1 license in use)
"avy_jtag" v1.5, vendor: AVERYDES, expiry: 30-apr-2024
user1 server6 /dev/pts/22 (v0.20220708) (license_server_1/1234 1491), start Wed 3/6 1:19
I'm using the command below:
awk 'BEGIN { printf "%-20s%-20s%-30s%-25s%-20s%-30s%-20s\n",
"License Name", "User", "Total Number of Licenses", "Number of license used", "Expiry Date", "License Checkout Date", "Servername" }
/Users of/ { license = $3; totallicense = $6; usedlicense = $11;
getline; getline;
next
}
/expiry/ {
expiry_date = $6; getline; getline; next
}
{ printf "%-20s%-20s%-30s%-25s%-20s%-30s%-20s\n",
license, $1, totallicense, usedlicense, expiry_date, $8" "$9" "$10, $2
}' /root/avery_lic_usage.log
However, it can't capture the "expiry" date on the line "avy_amba_portfolio" v1.5, vendor: AVERYDES, expiry: 30-apr-2024". Here's the sample output of the command:
License Name User Total Number of Licenses Number of license used Expiry Date License Checkout Date Servername
avy_amba_portfolio: user1 21 5 Tue 3/5 22:22 server1
avy_amba_portfolio: user1 21 5 Wed 3/6 1:19 server6
avy_amba_portfolio: user1 21 5 Wed 3/6 23:55 server1
avy_amba_portfolio: user1 21 5 Thu 3/7 0:03 server1
avy_amba_portfolio: user2 21 5 Thu 3/7 3:10 server1
avy_amba_portfolio: 21 5
avy_jtag: user1 6 1 Wed 3/6 1:19 server6
How can I make it work? Also, I want to remove the line on the output that has blank in user field.
The 1st
getline; getline; nextis tellingawkto skip over the next two lines of input, which in this case means theexpirylines are being ignored.Modifying the input to provide some visual differences in the data:
There's no need for the
getlinecalls if we can rely on unique patterns for the lines of interest.One
awkidea:This generates: