At 04:58 PM 11/14/01 -0500, Thomas Lewis wrote:
>Hello all.  I have a weird problem.  When I run this PERL one-liner by
>hand it prints everything within the appropriate range...
>
>perl -ne 'print if /NTHOST\)  Total/ .. /ANR0403I/' 
>/tmp/TIVOLI.OUT-activity-report
>
>This prints up the summary of a Tivoli backup for a Windows client
>pruned from the entire activity log.
>
>When I put this into a shell script it doesn't pick out each host it
>prints the entire activity log each time a host is called within the loop
>(there are 67 hosts for this one Tivoli server).
>
>#!/bin/bash
>
>TIVOLIOUT=/tmp/TIVOLI.OUT-activity-report
>
>HOSTNAMES=`perl -ne 'print if /ANE4952I/ .. /ANR0403I/' $TIVOLIOUT | awk
>-F: ' {print $5}' | awk -F\) ' {print $1}' | sort | uniq`
>
>##
>## Process the hostnames
>##
>
>for i in $HOSTNAMES
>do
>
>perl -ne 'print if /${i}\)  Total/ .. /ANR0403I/' $TIVOLIOUT > /tmp/blah.${i}]

Your problem is, of course, getting the $i inside the one-liner so that it 
is substituted by the time Perl sees it.  I find the shell quoting rules 
rather arcane, so I propose cheating:

perl -ne 'BEGIN{$host=shift} print if /$host\)  Total/ .. /ANR0403I/' $i 
$TIVOLIOUT > /tmp/blah.$i

I find that easier to understand... YMMV.

>I know I am using awk in here and this could probably be done in PERL but
>I am a beginner in PERL and am used to shell scripting.  If someone knows
>how to make this work within this shell script or knows how to do this
>entirely within PERL I would be very grateful.

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to