From: Brian Raven on
chris <ithinkiam(a)gmail.com> writes:

> On 14/06/10 18:38, Dean wrote:
>> I want to invoke the following from a Bash script:
>>
>> START='[14/Jun/2010:00:00:00]'
>> FINISH='[14/Jun/2010:23:59:59]'
>> perl -ne ' print if ( $_ ge "$START"&& $_ le "$FINISH" ) ' $LOGFILE
>>
>> I want Bash to substitute the $START, $FINISH& $LOGFILE variables and leave
>> the $_ to perl.
>>
>> How should I quote/escape that perl command?
>
> Not sure explicitly, but if you stored START and FINISH as environment
> variables you could use $ENV{} instead:
>
> export START='[14/Jun/2010:00:00:00]'
> export FINISH='[14/Jun/2010:23:59:59]'
> perl -ne ' print if ( $_ ge "$ENV{START}"&& $_ le "$ENV{FINISH}" ) '
> $LOGFILE
>
> However, why do it all within perl? Why do you need the bash
> substitutions for START and FINISH?
>
> perl -ne 'BEGIN { $start = "[14/Jun/2010:00:00:00]"; $finish =
> "[14/Jun/2010:23:59:59]";} print if ( $_ ge "$start"&& $_ le
> "$finish" ) ' $LOGFILE

You could try using the Env module to import those environment variables:

perl -MEnv=START,FINISH -ne 'print if $_ ge $START && $_ le $FINISH' \
$LOGFILE

HTH

--
--
Brian Raven