[Israel.pm] awk equivalent

Gaal Yahas gaal at forum2.org
Mon Mar 22 12:11:16 PST 2004

On Mon, Mar 22, 2004 at 04:09:33PM +0200, Yossi.Itzkovich at ecitele.com wrote:
> Hi,
> What is the Perl equivalent of:
> 1. awk '{print $3}'  filename
> and
> 2. awk -Fc '{print $3}'  filename   ( "c" is single delimiter character)
> I know how to get it done in Perl, but my question is about "equivalent"
> code.

TMTOWTDI, but you could do:

1. perl -lne 'print ((split)[2])'
2. perl -lne 'print ((split 'c')[2])'

There's also a -F switch to perl; see perlrun.

And if you're looking for Perl equivalents to awk in general, check out
a2p, which "takes an awk script specified on the command line (or from
standard input) and produces a comparable perl script on the standard

Gaal Yahas <gaal at forum2.org>

More information about the Perl mailing list