Re: Perl one-liner to print columns
- From: daggerquill@xxxxxxxxx (Jay Savage)
- Date: Mon, 25 Apr 2005 13:38:55 -0400
On 4/25/05, Jay Savage <daggerquill@xxxxxxxxx> wrote:
> On 4/25/05, Larsen, Errin M HMMA/IT <errinlarsen@xxxxxxxxxxx> wrote:
> > Hi Perlers,
> >
> > I typically will type the following to collect a specific column of
> > data from some command's output:
> >
> > # some_command | awk '{print $4}'
> >
> > I wanted to start using perl one-liners more often, so I thought I'd
> > try the column thing first. This is what I came up with:
> >
> > # some_command | perl -pe '$_ = (split)[3] . "\n";'
> >
> > That feels/seems rather awkward. Is there an easier, "cleaner" way of
> > doing this?
> >
> > --Errin
>
> perl -pae '$_="$F[3]\n"'
> perl -nae 'print "$F[3]\n"'
>
> See perldoc perlrun for info on the -a and -F switches.
>
> HTH,
>
> --jay
>
Also, I feel like I should mention:
perl -lnae 'print $F[3]' #and
perl -lpae '$_ = $F[3]'
Which are more awkish and arguably less typing, but be careful with
the -0 switch when using them. Again, perldoc perlrun covers the
details.
Best,
--jay
.
- References:
- Perl one-liner to print columns
- From: Errin M HMMA/IT Larsen
- Perl one-liner to print columns
- Prev by Date: Very basic question about running perl cgi on tomcat
- Next by Date: Perl One-liner de-compile?
- Previous by thread: Re: Perl one-liner to print columns
- Next by thread: Very basic question about running perl cgi on tomcat
- Index(es):
Relevant Pages
|