Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: grep command

by davidrw (Prior)
on Jan 18, 2007 at 14:32 UTC ( [id://595260]=note: print w/replies, xml ) Need Help??


in reply to Re: grep command
in thread grep command

just cheat and make sure the input doesn't have more than one per line :)
tr ' ' '\n' < /tmp/hh | grep -c hello
alternatives:

plain, explicit count (leverage s/// to provide # per line):
perl -lne '$ct += s/hello//g; END {print $ct}' /tmp/hh
Same technique as the tr/grep above, just in perl flavor:
perl -0040 -ne 'END {print "$x\n"} $x++ if /hello/' /tmp/hh
Fun w/perlrun:
perl -Fhello -0777 -lane 'print $#F' /tmp/hh # shorter: perl -apFhello -0777e '$_=$#F' < /tmp/hh # with check for word boundry (e.g. to exclude "Othello" or mispelled +"cello") perl -apF'\bhello\b' -0777e '$_=$#F' < /tmp/hh

Replies are listed 'Best First'.
Re^3: grep command
by shmem (Chancellor) on Jan 18, 2007 at 14:36 UTC
    perl -lne '$ct += s/hello//g; }{print $ct' /tmp/hh

    ;-)
    --shmem

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://595260]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-23 16:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found