Search file for strings

nnCron and nnCron LITE discussion

Search file for strings

Postby swiss » Mon, 11 Feb 2008, 13:43

Hi There,

I would like to search a huge file for a particular string and get the position of each string found . I am not sure how i can archive a loop correctly.

What i have so far:

max-line-size ALLOCATE THROW TO list-contents
S" %FOUND-FULLPATH%" EVAL-SUBST R/O OPEN-FILE-SHARED THROW TO list-file
BEGIN list-contents max-line-size 2- list-file READ-LINE THROW WHILE
list-contents + 0 SWAP C!

-- and then something like that
BEGIN WHILE (finding str)
--- get me the exact position within the file of the found string
--- str StringGetPos position !


REPEAT

I would appreciate some help with possible example code, as this is currently just over my head.

Thanks a lot!

Matt
swiss
 
Posts: 12
Joined: Mon, 11 Dec 2006, 14:41

Re: Search file for strings

Postby SeMa » Mon, 11 Feb 2008, 18:52

Generally that's right idea.

Code: Select all
VARIABLE ln_number   \ line number
...
Action:
...
max-line-size ALLOCATE THROW TO list-contents
ln_number 0!
FOUND-FULLPATH R/O OPEN-FILE-SHARED THROW TO list-file
BEGIN list-contents max-line-size 2- list-file READ-LINE THROW WHILE
  list-contents + 0 SWAP C!
  ln_number 1+!          \ incrementing line number
  ln-contents ASCIIZ> str StringGetPos position DUP ! NOT
  IF
    LOG: "mylogfile.log" "string found at %ln_number @%:%position @%"
  THEN
REPEAT
...
Компьютер ─ устройство, разработанное для ускорения и автоматизации человеческих ошибок
User avatar
SeMa
 
Posts: 637
Joined: Fri, 15 Apr 2005, 12:49
Location: Украина

Re: Search file for strings

Postby swiss » Tue, 12 Feb 2008, 05:28

Thanks for your reply,

I might have been too optimistic, though, the files i am trying to find specific strings are not usual text files, therefore one line can be several thousands characters long. Therefore a particular string can be also found several times within one line.

What i would like to archive is, finding the position of each particular string within this single line.

Is this possible?

Thanks.

Matt
swiss
 
Posts: 12
Joined: Mon, 11 Dec 2006, 14:41

Re: Search file for strings

Postby SeMa » Tue, 12 Feb 2008, 15:30

Now I can't conceive how it could made :rolleyes:
Компьютер ─ устройство, разработанное для ускорения и автоматизации человеческих ошибок
User avatar
SeMa
 
Posts: 637
Joined: Fri, 15 Apr 2005, 12:49
Location: Украина

Re: Search file for strings

Postby swissiws » Tue, 16 Sep 2008, 10:08

BTW,,,,

SED.EXE was the answer... what a powerful command line toy to search for characters/ replace etc etc... and fast.

Cheers.

Matt
swissiws
 
Posts: 5
Joined: Tue, 16 Sep 2008, 05:55


Return to nnCron forum (English)

Who is online

Users browsing this forum: No registered users and 0 guests