The Poker Copilot Blog

Tracking the development of Poker Copilot, Mac OS X software for poker analysis and statistics.

Monday, 28 July 2008

Question for a Unix Command Line Tool Expert

Unix command line tools have never been a strong area for me. Who can suggest a solution to the following problem?

I have many text files in a folder. I would like to list a count of how many lines a certain regular expression matches within each file. The output would be something like this:

file1.txt: 23
file2.txt 0
file3.txt 37

I'm sure there must be a way using grep, sort, wc, and so on, without resorting to a for loop in a script file. However I haven't found it yet.

2 comments:

Mark L. Smith said...

Try this:

find . -maxdepth 1 -name '*.txt' -print -exec sh -c 'cat $1 | tr " " "\n" | grep mark | wc -l' {} {} \;

Steve McLeod said...

Thanks for the help, Mark. While trying to adapt your suggestion, I accidentally discovered that grep alone does exactly what I want, once I have the command line parameters correct:

grep -c '[my regular expression]' *.txt

 

Poker Copilot

Free 30 Day Trial

Only $69

Order risk free with our 30-day money back guarantee.

  • Poker tracking software for Mac OS X
  • Supports PokerStars, Winamax, Merge Network, Ongame Network
  • Analyses your opponents while you play
  • On-table HUD for Mac
  • Easy to use, easy to understand

Watch a demo of the major features of Poker Copilot