regex line by line over file
James Smith
bjlockie at lockie.ca
Thu Mar 27 00:14:03 EDT 2014
On Wednesday, March 26, 2014 11:23:29 PM UTC-4, James Smith wrote:
> I can't get this to work.
>
> It runs but there is no output when I try it on a file.
>
>
>
>
>
> #!/usr/bin/python
>
>
>
> import os
>
> import sys
>
> import re
>
> from datetime import datetime
>
>
>
> #logDir = '/nfs/projects/equinox/platformTools/RTLG/RTLG_logs';
>
> #os.chdir( logDir );
>
>
>
> programName = sys.argv[0]
>
> fileName = sys.argv[1]
>
>
>
> #pattern = re.compile('\s*\\"SHELF-.*,SC,.*,:\\"Log Collection In Progress\\"')
>
> re.M
>
> p = re.compile('^\s*\"SHELF-.*,SC,.*,:\\\"Log Collection In Progress\\\"')
>
> l = ' "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"'
>
>
>
> # this works :-)
>
> m = p.match( l )
>
> if m:
>
> print( l )
>
>
>
> # this doesn't match anything (or the if doesn't work) :-(
>
> with open(fileName) as f:
>
> for line in f:
>
> # debug code (print the line without adding a linefeed)
>
> # sys.stdout.write( line )
>
> if p.match(line):
>
> print(line)
>
>
>
>
>
> The test file just has one line:
>
> "SHELF-17:LOG_COLN_IP,SC,03-25,01-18-58,NEND,NA,,,:\"Log Collection In Progress\",NONE:1700000035-6364-1048,:YEAR=2014,MODE=NONE"
I tried the re.M in the compile and that didn't help.
More information about the Python-list
mailing list