From: William James Date: 2007-09-20T03:20:04+09:00 Subject: Re: finding string matches, in order, in a file On Sep 19, 1:06 pm, William James wrote: > On Sep 19, 11:20 am, Peter Bailey wrote: > > > William James wrote: > > > On Sep 19, 7:03 am, Peter Bailey wrote: > > > >> .. > > > Very odd. "scan" will return the strings in the order that > > > they are found. > > > > How did your program read the file? Could its contents have > > > been disordered somehow? After your program reads the file > > > into a string, have it write the string to a temp file and > > > then use fc or diff to compare the 2 files. > > > > "Health Issues" appears twice; I presume the file contains > > > two entries. > > > > You've probably had your editor do a string search to verify > > > that "Immigration" isn't the first entry in the file. > > > Yes, as I said yesterday, the word "Immigration" is on line 300+, and, > > the first entry that should be seen is the "Trade" one. > > > Before I do this scan, I do a sweep where I delete all the extra white > > space at the beginning of each line. There's a lot of it there. I've > > tried this without that sweep, but, I get the same results, especially > > after, with your help, I was more generic in my definition of the white > > space around these entries. > > > I did a write of this array as a string to a file. When I pulled up the > > file, it looks exactly like the output of my script. > > "Health Issues" appears twice in your output. Returning to my > original > hypothesis, are you certain "Trade" doesn't occur twice in the file? > If it occurs twice, and the reg.ex. fails to match the first instance > but matches the second, it may appear to you that "Trade" is being > output out of order, when in fact the first occurrance is simply > missing. > If there are more copies of each entry in the file than you suspect, > a faulty reg.ex. will make it seem that the output is out of order. A way to see if the reg.ex. is matching all entries. grep -c '