Ok. Coding the whole thing in perl would look something like this (I'm not
testing this program, so watch out for small errors):
#!/usr/bin/perl
open (INFILE,"/fullpath/filename") ;
while ( $nextline = <INFILE> )
if ( $nextline ~= m/grepstring/ )
{
$resultline = nextline ;
} ;
$printline = substr($resultline,4,6) ;
print "$resultline\n" ;
close INFILE ;
# EOP
This (or something close to it) will put in the variable $printline the
contents of characters 4-9 (perl character numbering starts with 0, not 1)
in $resultline, which will contain the LAST line in the file that contains
the string "grepstring".
At 10:18 PM 2/20/99 +0200, Raider wrote:
[original question]
>
> > Could someone tell me hwo this script line:
> >y=`grep "some string" file | tail -n 1 | cut -b5-10`
>On Sat, 20 Feb 1999, Ray Olszewski wrote:
>> Actually, the line won't work in perl *as written* because two details are
>> wrong:
>> 1. y is not a legal variable name in perl; it has to be $y
>> 2. in perl, lines have to end with semi-colons
>
> I know these things. They are pretty well explained in the manual
>I have. That was a shell script line. And I wanted to know how would
>look the perl script that does the same. I mean how it will look the part
>of the script that will search inside of a file (eventually open it) an
>arbitrary string, it will chose the last line found and put in a scalar
>the charaters of a defined field. Can this be done only in perl? Without
>the help of extranal commands?
------------------------------------"Never tell me the odds!"---
Ray Olszewski -- Han Solo
762 Garland Drive
Palo Alto, CA 94303-3603
650.321.3561 voice 650.322.1209 fax [EMAIL PROTECTED]
----------------------------------------------------------------