Shell Variables in AWK Expressions?
Paul_Melson@keykertusa.com
Paul_Melson@keykertusa.com
Mon, 1 Oct 2001 14:58:47 -0400
OK, I found the answer in the com.psys.unix FAQ, in a section titled,
obviously enough, "Is it possible to pass shell variable settings into an
awk program?"
(http://www.faqs.org/faqs/unix-faq/faq/part3/section-12.html)
Indeed it is. Turns out I needed to wrap the variable in 's like so:
loop=`wc -l column1_txt | cut -c5-7`
pool=1
while [ $loop -ge $pool ]; do
for file in 1 2 3 4 5 6 7 8
do
out=`awk 'NR == '$pool'' column${file}_txt`
echo -n "${out},"
done
echo
pool=`expr $pool + 1`
done
It's not pretty, but this is working code. I can now pull NetBackup for
UNIX "Client Backup" report logs into Excel as comma-delimited text. If
anyone wants the script for their own use, please e-mail me. It takes
this:
Client: Server1
Backup ID: Server1_1001734140
Class: Solaris_PDGS
Class Type: Standard
Sched Label: full
Schedule Type: Full Backup
Retention Level: 1 month (3)
Backup Time: 09/28/2001 23:29:00
Elapsed Time: 014:26:51
Expiration Time: 10/29/2001 22:29:00
Compressed: yes
Encrypted: no
Kilobytes: 20042814
Number of Files: 177200
Primary Copy: 1
Image Type: 0 (Regular)
Keyword: (none specified)
Ext Security Info: no
File Restore Raw: no
Image Dump Level: 0
File System Only: no
Object Descriptor: (none specified)
Multiplexed: no
TIR Available: yes (on disk)
And turns it into this:
Server1_1001734140,Solaris_PDGS,Server1,full,09/28/2001
23:29:00,177200,20042814,014:26:51
Thanks to all those who offered suggestions.
PaulM