[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Favorite commands: wc
On Fri, Jan 04, 2002 at 04:04:00PM -0600, Flood Randy Capt AFCA/TCAA wrote:
> For example,
>
> "cat foo.txt|grep the | wc -l"
>
> will tell you the number of lines that contain the word "the" in the
> file foo.txt. You can do this slightly more compactly without using
> cat, but I used it for clarity.
GNU grep also has a "-c" option that can be used to trim your example
down to just
grep -c the foo.txt
> I'd like to see someone talk about awk and sed. I used to know how to
> do nifty stuff with them, but then I discovered Perl...
There are still a few things that are somewhat easier to do in awk
than in perl. The biggest thing is extracting specific fields of
input... For example, this will print the first, fifth, and ninth
field of ls -l output (the permissions, size, and filename):
ls -l | awk '{print $1,$5,$9}'
The same thing in Perl is a bit longer...
ls -l | perl -alne 'print "@F[1,5,9]"'
or
ls -l | perl -alpe '$_="@F[1,5,9]"'
Either way, it's also a bit harder to remember. :-)
Steve
--
steve@silug.org | Southern Illinois Linux Users Group
(618)398-7360 | See web site for meeting details.
Steven Pritchard | http://www.silug.org/
-
To unsubscribe, send email to majordomo@silug.org with
"unsubscribe silug-discuss" in the body.