#137168 - 2005-04-05 06:50 PM
Re: Help: Scan text files for a number combination
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4567
Loc: USA
|
Just thinking out loud... here's some pseudo code...
Code:
$number=1234567 open($file) $=readline() $found=0 while @error =0 and $found=0 if instr($,$number) $found=1 endif $=readline() loop close()
|
|
Top
|
|
|
|
#137170 - 2005-04-05 06:59 PM
Re: Help: Scan text files for a number combination
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
$number = "somevalue" $dir = enumdir("some dir") for each $file in $dir $content = readfile($file) for each $line in $content if instr($line,$number) ? $file endif next next
or something like that...
|
|
Top
|
|
|
|
#137171 - 2005-04-05 07:10 PM
Re: Help: Scan text files for a number combination
|
maciep
Korg Regular
   
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
do you know what number you're looking for?
Code:
$theDir = 'c:\' $txtFile = dir($theDir + '*.txt') while @error = 0 $ = open(1,$theDir + $txtFile) $line = readline(1) While @error = 0 for $j = 1 to len($line)-7 $possibleNumber = substr($line,$j,7) if $possibleNumber = 0.0 + $possibleNumber ? $possibleNumber endif next $line = readline(1) loop $ = close(1) $txtFile = dir() loop
|
|
Top
|
|
|
|
#137175 - 2005-04-06 01:13 AM
Re: Help: Scan text files for a number combination
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Masken, minor update to maciep's code.
It does appear to work even with binary files in the folder.
I added line to show which file contains the entry. But seems to find the length of numbers anywhere in the file as you requested.
Nice job maciep.
Code:
Dim $theDir, $txtFile, $, $line, $j, $possibleNumber $theDir = 'c:\numtest\' $txtFile = dir($theDir + '*.*') while @error = 0 $ = open(1,$theDir + $txtFile) $line = readline(1) While @error = 0 for $j = 1 to len($line)-7 $possibleNumber = substr($line,$j,7) if $possibleNumber = 0.0 + $possibleNumber ? $txtFile + ' ' + $possibleNumber endif next $line = readline(1) loop $ = close(1) $txtFile = dir() loop
|
|
Top
|
|
|
|
#137177 - 2005-04-06 06:11 AM
Re: Help: Scan text files for a number combination
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
DOH! Thanks Howard. We have so many UDFs that I guess we sometimes forget what they all do. 
But Maciep's code does appear to fit the bill as well in my simple tests.
|
|
Top
|
|
|
|
#137178 - 2005-04-06 02:33 PM
Re: Help: Scan text files for a number combination
|
maciep
Korg Regular
   
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
Actually, my code didn't seem to like numbers that started with '0'. So I made some adjustments
Code:
$theDir = 'c:\' $txtFile = dir($theDir + '*.txt') while @error = 0 $ = open(1,$theDir + $txtFile) $line = readline(1) While @error = 0 for $j = 1 to len($line)-6 $possibleNumber = substr($line,$j,7) $asNum = 0.0 + $possibleNumber if $possibleNumber = padstr($asNum,'0', len($possibleNumber)) ? $txtFile + ' ' + $possibleNumber endif next $line = readline(1) loop $ = close(1) $txtFile = dir() loop
Function PadStr($Input, $Pad, $Length, optional $PadSide) Dim $i, $x $PadStr = "" $Input = "" + $Input $Pad = "" + $Pad $Length = 0 + $Length If $PadSide="" or Len($PadSide)>1 or Instr("LR",$PadSide)= 0 $PadSide = "L" Endif
$x = Len($Input)
For $i=$x to $Length - 1 Step Len($Pad) If $PadSide = "L" $Input = $Pad + $Input Else $Input = $Input + $Pad Endif Next If $PadSide = "L" $Input = Right($Input, $Length) Else $Input = Left($Input, $Length) Endif $PadStr = $Input Exit 0 Endfunction
|
|
Top
|
|
|
|
#137180 - 2005-04-08 12:08 AM
Re: Help: Scan text files for a number combination
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11631
Loc: CA
|
Well not KiX friendly but cool program for non Unix types.
RegexBuddy
Using the latest version of the code posted by Maciep also grabs the number and says which file. But if Howard's works better for you that's cool too. Getting the task done is what counts.
|
|
Top
|
|
|
|
#137181 - 2005-04-08 01:09 AM
Re: Help: Scan text files for a number combination
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Masken, are you saying the number could be split across lines? I would like to determine why the code I pointed you to didn't work.
Could you post your regex solution. I think that it would be useful for others that may have similar problems.
|
|
Top
|
|
|
|
#137183 - 2005-04-09 12:09 AM
Re: Help: Scan text files for a number combination
|
masken
MM club member
   
Registered: 2000-11-27
Posts: 1222
Loc: Gothenburg, Sweden
|
@Howard, nono, not split across lines, but anywhere horisontal or vertical within the file, always non-splitted though 
I just used the RegEx function you had 
Code:
CALL "@SCRIPTDIR\RegEx.udf"
$SourceFile = "E:\MyTextFile.txt" $ArrSourceFile = ReadFile($SourceFile)
FOR EACH $TextLine IN $ArrSourceFile $ArrMatches = RegExpFind("\d{7}", $TextLine, $1, 1) FOR EACH $Match IN $ArrMatches ? "Match = " + CHR(34) + $Match[0] + CHR(34) NEXT NEXT
FUNCTION ReadFile($File) DIM $Handle, $null, $Text $Handle = FREEFILEHANDLE() $null = OPEN($Handle, $File) IF @ERROR EXIT @ERROR ENDIF DO $Text = $Text + @CRLF + READLINE($Handle) UNTIL @ERROR $null = CLOSE($Handle) $ReadFile = SPLIT(SUBSTR($Text, 1), @CRLF) ENDFUNCTION
Edited by masken (2005-04-09 12:17 AM)
_________________________
The tart is out there
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 271 anonymous users online.
|
|
|