[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: man grep
Jay Link said:
> cat /etc/passwd | perl -e 'while (<>) { ($one, $two, $three, $four) =
> split (/:/, $_, 4); print if ($three <= 150); }'
Or maybe
perl -ne 'print if ((split /:/)[2]<=150);' /etc/passwd
Actually, the original mail said that the third field should be
between 1 and 150, so the following would be a little better:
perl -ne '$n=(split /:/)[2]; print if (($n>0)&&($n<=150));' /etc/passwd
But we can also use some Perl command line options to shorten that
down a bit...
perl -F: -ane 'print if (($F[2]>0)&&($F[2]<=150));' /etc/passwd
And just so people don't think I'm a complete Perl bigot (even if I am
;), here's the same thing using awk:
awk -F: '{if (($3>0)&&($3<=150)){print}}' /etc/passwd
Steve
--
steve@silug.org | Linux Users of Central Illinois
(217)698-1694 | Meetings the 4th Tuesday of every month
Steven Pritchard | http://www.luci.org/ for more info
--
To unsubscribe, send email to majordomo@luci.org with
"unsubscribe luci-discuss" in the body.