grab.awk translated to PERL
grab.awk translated to PERL
- PERL has no match() function similar to awks’s
- Notice the special variables referenced for calculating:
- Length of Pattern Match
- $& is the string matched by the last pattern match
- We use the PERL length() function on $&
- Starting Point
- $` is the string preceding the last pattern match
- Start point equals length of preceding string + 1
#!/usr/local/bin/perl
$[ = 1; # set array base to 1
$, = ' '; # set output field separator
$\ = "\n"; # set output record separator
while (<>) {
chop; # strip record separator
if (/^(cme|cbt|lif|smx)/) {
$start_point = $_ =~ '[0-9][0-9][0-9][0-9][0-9]+' &&
($RLENGTH = length($&), $RSTART = length($`)+1);
print $RSTART, $RLENGTH . ': ' . $_;
}
}