#156933 - 2006-02-08 02:10 PM
Re: Search entire text file?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
How about this: Code:
Break ON $asSearchStrings="B","E" If Open(1,"inv.txt") "Cannot open file for reading ["+@ERROR+"] "+@SERROR+@CRLF Else $sLine=ReadLine(1) While Not @ERROR $asLine=Split($sLine+" ") If 1+AScan($asSearchStrings,$asLine[1]) "Match: "+$asLine[1]+" First="+$asLine[0]+" Second="+$asLine[1]+" Third="+$asLine[2]+@CRLF EndIf $sLine=ReadLine(1) Loop EndIf
Results:
Quote:
Match: B First=a Second=B Third=c Match: E First=d Second=E Third=f Match: E First=g Second=E Third=h
|
|
Top
|
|
|
|
#156935 - 2006-02-08 03:23 PM
Re: Search entire text file?
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
readfile() UDF FilterArray() UDF
$file=readfile("inv.txt") $filtered=filterarray($file,' B ') for each $item in $filtered ? $item next
|
|
Top
|
|
|
|
#156938 - 2006-02-08 03:41 PM
Re: Search entire text file?
|
JazzM
Getting the hang of it
Registered: 2004-04-23
Posts: 91
|
Intressting. Radimus code works, BUT in opposite way! It filters the input search string line and print out the rest of file content.
But I need the input search string line values!
_________________________
I will always look out from behind these eyes...
|
|
Top
|
|
|
|
#156939 - 2006-02-08 03:42 PM
Re: Search entire text file?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
readfile() UDF FilterArray() UDF
$file=readfile("inv.txt") $filtered=filterarray($file,' B ') for each $item in $filtered ? $item next
This will return lines with "B" in fields other than field 2, which may or may not be an issue depending on the data.
|
|
Top
|
|
|
|
#156940 - 2006-02-08 03:57 PM
Re: Search entire text file?
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
@Richard: if " b " has a delimiter (spaces around it) then that may not be the case
@Jazz use the optional parameter for filterarray... $filtered=filterarray($file,' B ',1)
Sorry about that
|
|
Top
|
|
|
|
#156941 - 2006-02-08 04:03 PM
Re: Search entire text file?
|
JazzM
Getting the hang of it
Registered: 2004-04-23
Posts: 91
|
Richard, I dont get any output from you code. There is one space between each letter in the inv.txt file.
No output!
_________________________
I will always look out from behind these eyes...
|
|
Top
|
|
|
|
#156944 - 2006-02-09 09:22 AM
Re: Search entire text file?
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
richie's code does not work as it splits with double space. remove the another space and it should work fine.
Eh? No it doesn't! That's a "+", not a ","
The sample output was from a real run, so I know it works.
While I'm intrigued about the reasons it doesn't work for JazzM he has another solution which appears to satisfy him.
|
|
Top
|
|
|
|
#156946 - 2006-02-13 05:08 PM
Re: Search entire text file?
|
JazzM
Getting the hang of it
Registered: 2004-04-23
Posts: 91
|
Im working to adapt Radimus solution. However i will try to determine why i cannot make Richards code work.
Thanx a lot all of u :-)
_________________________
I will always look out from behind these eyes...
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 987 anonymous users online.
|
|
|