Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about searching in txt-file
#1
Hi there,

Is it possible to search in a big txt-file for something and when its found to extract the line to a string for further use? I have no idea where to start...

So an example the file big.txt and in this file i'm looking for 'quickmacros' and anything what is on that line till linebreak has to be copied in a string.

Any help is appreciated
#2
Macro Macro1474
Code:
Copy      Help
str f="$temp$\big.txt"
str String="quickmacros"

;----------------------------

;This code creates file for testing. Delete this code if you already have the file.

_s=
;qqqq wwwww
;eee quickmacros ffffffff
;gggg hhhhhhhh
if !dir(f)
,_s.setfile(f)

;----------------------------

str s.getfile(f) line
if(findrx(s F"^.*\Q{String}\E[^\r\n]*$" 0 8 line)<0) out F"''{String}'' not found."; ret
out line
#3
Thank you for this example. The ordinary text (\Q\E) stuff is exactly what I've been missing while using regular expressions. The whole darn thing just became a lot more clear.

Is there anyway to output the line number in this example?
#4
No, need to search in each line.

int i=0; str s2
foreach s2 s
,i+1
,if(findrx(s2...)<0) continue
,out s2


Forum Jump:


Users browsing this thread: 1 Guest(s)