View Single Post

   
  #7 (permalink)  
Old 02-19-2008, 09:20 PM
Jeffrey Froman
 
Posts: n/a
Default Re: OT How to count occurances in a text file

buck wrote:

> Can you please help me determine where there are unmatched quotes (")
> in my .mailfilterrc file?
>
> grep -c returns the number of lines where the " appears, but I need
> something that counts the number of instances of " per line.


(Message sent with lines unwrapped)

Here's a python one-liner that can be run from the command line. It
will return a list of all line numbers in "myfile" which contain a
non-even number of double quotation marks:

python -c 'print [e for e, line in enumerate(open("myfile")) if line.count("\"") % 2]'


Hope that works for you,
Jeffrey
Reply With Quote