Quote:
Originally Posted by casperdaghost
Alot of time I use a perl one liner like a grep at the end of a cat or more to print specific text from a log or config file. It works great.
more myfile | perl -nle 'print /(regex)/'
|
tip for you, there's a tool called a2p you can use to translate awk to Perl code. Eg, awk
Code:
c&&c--;/^Alas/{c=5}
put this as a script, eg myscript.awk, then on command line
Code:
$ a2p test.awk
#!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if $running_under_some_shell;
# this emulates #! processing on NIH machines.
# (remove #! line above if indigestible)
eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
# process any FOO=bar switches
while (<>) {
print $_ if $c && $c--;;
if (/^Alas/) {
$c = 5;
}
}
what you need is the while(<>) part.
Code:
$ cat test1.pl
#!/usr/bin/perl -w
while (<>) {
print $_ if $c && $c--;
if (/^Alas/) {
$c = 5;
}
}
$ perl test1.pl file