forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Getting some text from a Text File

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
kc7aad
Contributor
Contributor


Joined: 09 Oct 2005
Posts: 53
Location: Spokane Washington

PostPosted: Mon May 21, 2007 10:24 pm    Post subject: Getting some text from a Text File Reply with quote

I'm sure this is gonna be easy, but I have spent lotsa time trying, and juts can't grasp my hands around this.. I need to strip a line of text out of a file. It's a simple .txt file at that!!
Here is an example of the text I have:
4954 page sent 08:46:13a 4 12BA 0,000AN p3 1991277 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
4976 page sent 08:46:14a 4 12BA 0,000AN p3 1991316 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
4978 page sent 08:46:14a 4 12BA 0,000AN p3 1991588 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
4972 page sent 08:46:15a 4 12BA 0,000AN p3 1991284 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
4920 page sent 08:46:15a 4 12BA 0,000AN p3 1991285 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
4981 page sent 08:46:15a 2 12BA 0,000AN p3 1991564 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
4952 page sent 08:46:16a 4 12BA 0,000AN p3 1991261 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
4474 page sent 08:46:16a 4 12BA 0,000AN p3 1991192 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)


This is an output of My in-house paging system loging file, and I want to be able to send things using Cellular SMS as well as thru to the pagers. In case someone doesn't want to carry a pager, and rather their cell phone.
The good news, is the Text portion of what I really want to send to the End User, is already defined as to how long it is. See the "D 36" in the messages... The "D" I believe stands for Digital, and the 36 is how many charachters are in the message.
So the first 4 numbers is the pager number itself. So if somehow I can search for thatin the text file, then go to the "D", figure out how many charachters I need to get, then copy the text and send it in a variable?
The rest of the text is pretty useless for what I ned to send to "Normal" users, but may be nice to ba able to send the some Technical People, in case we are doing trouble shooting. That's just an extra, though.

Hopefully this make some sense to yo, and someone will have an idea!

Thanks in advance...

Rod
Back to top
View user's profile Send private message Yahoo Messenger
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Tue May 22, 2007 2:42 am    Post subject: Reply with quote

It looks like the lines are always the same length so something like this should work:
Code:

  REM Change %%pagefile to reflect the path of your page log.
  %%pagefile = Page.txt
  DIALOG CREATE,Pager Test,-1,0,550,320
  DIALOG ADD,LIST,LIST1,88,7,538,225,,CLICK
  DIALOG ADD,TEXT,TEXT1,10,215,,,Pager:
  DIALOG ADD,EDIT,pagerNum,8,250,52,19,,Enter pager number to search for.
  DIALOG ADD,BUTTON,pagerSearch,8,305,50,19,Search,,DEFAULT
  DIALOG ADD,TEXT,TEXT2,35,105,,,Page sent at:
  DIALOG ADD,EDIT,pageTime,33,172,88,19,,Time page was sent.
  DIALOG ADD,TEXT,TEXT3,35,267,,,Sent:
  DIALOG ADD,EDIT,pageData,33,296,245,18,,What was sent.
  DIALOG ADD,TEXT,TEXT4,60,145,,,Technical:
  DIALOG ADD,EDIT,pageTech,58,195,195,19,,Technical data.
  DIALOG SHOW
  list loadfile,LIST1,%%pagefile
  list seek,LIST1,0
  gosub fillData
:evloop
  wait event
  goto @event()
:LIST1CLICK
  gosub fillData
  goto evloop
:pagerSearchBUTTON
  %%sel = @index(LIST1)
  dialog clear,pageTime
  dialog clear,pageData
  dialog clear,pageTech
 
  %x = 0
  %%found = 0
  %%searchNum = @dlgtext(pagerNum)
  repeat
    %%tmppagerNum = @substr(@item(LIST1,%x),1,4)
    if @equal(%%tmppagerNum,%%searchNum)
      gosub fillData
      %%found = 1
    end
    %x = @succ(%x)
  until @equal(%x,@count(LIST1))@equal(%%found,1)
 
  if @equal(%%found,0)
    list seek,LIST1,%%sel
  end
  goto evloop
:Close
  exit
:fillData
  %%pagerNum = @substr(@item(LIST1),1,4)
  %%pageTime = @substr(@item(LIST1),16,24)
  %%pageTech = @substr(@item(LIST1),26,50)
  %%pageData = @substr(@item(LIST1),57,@len(@item(LIST1)))
  dialog set,pagerNum,%%pagerNum
  dialog set,pageTime,%%pageTime
  dialog set,pageData,%%pageData
  dialog set,pageTech,%%pageTech
  exit


Updated to allow searching per pager number.

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Tue May 22, 2007 3:09 am    Post subject: Reply with quote

Or if the message text always starts with a tilde you could use something like:

Code:
  REM Change %%pagefile to reflect the path of your page log.
  %%pagefile = Page.txt
  list create,1
  list loadfile,1,%%pagefile
  list seek,1,0
  %%Pager = @input(Enter the 4 digit pager ID number)
  %x = @match(1,%%Pager)
  %x = @item(1)
  option fieldsep,"~"
  parse "%a;%%Message",%x
  %%Message = "~"%%Message
  info Message to Pager %%Pager is @cr()@cr()%%Message
  stop

_________________
cheers

Dave
Back to top
View user's profile Send private message
kc7aad
Contributor
Contributor


Joined: 09 Oct 2005
Posts: 53
Location: Spokane Washington

PostPosted: Wed May 23, 2007 1:08 am    Post subject: Reply with quote

Well thanks guys for the responses. However, it's not quite what i'm looking for. I need to be able to search the text file (Hopefully in the background), then be able to output the result'd query to a variable. I have it working somewhat already with the code:

Code:

LIST CREATE, 1
 LIST LOADFILE, 1,C:\ROD.BUF
 %M = @MATCH(1,4972)
 INFO %M
# %I = @ITEM(1)  #Use this for debuging
 run CMDMSGR.EXE -tEkholm.Rod -m%I,PIPE
 %P = @PIPE()
 INFO %I @CR() %P
 LIST CLOSE, 1


So now the problems is, When It tries to pass the variable %I to the command line, I am only getting the first word, or in this case the "4972" that it passes. I can't get it to pass the entire line. I tried several different combinations of quotes, and can't seem to get anything to work.

Once I get this to work, I think I can put in a timer and have it check the file every xx seconds. The only other part I need to figure out, is I only need to to look at say the 1st 10 lines of this text file. Do-able?

Thanks
Back to top
View user's profile Send private message Yahoo Messenger
Hooligan
VDS Developer
VDS Developer


Joined: 28 Oct 2003
Posts: 480
Location: California

PostPosted: Wed May 23, 2007 1:30 am    Post subject: Reply with quote

Without knowing how the switches on "CMDMSGR.EXE" work, I can only speculate as to what might be happening... Perhaps the "-m" switch delimits at the first <space> character, in which case I'd run your text through a filter and replace all the <spaces> with underscores (_).

If the text file is large, you may want to open it with @binfile(), otherwise it would be much easier to load it into a list (as you are doing) and ignore anything beyond the first 10 lines.

Hooligan

_________________
Hooligan

Why be normal?
Back to top
View user's profile Send private message
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed May 23, 2007 2:11 am    Post subject: Reply with quote

Try:
Code:

%I = @chr(34)@ITEM(1)@chr(34)

You could put the variables from my code together, so you could pass only the parts of the line that you want.

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
kc7aad
Contributor
Contributor


Joined: 09 Oct 2005
Posts: 53
Location: Spokane Washington

PostPosted: Wed May 23, 2007 2:22 am    Post subject: Reply with quote

I was thinking I should elaborate a little more... CMDMSGR.EXE uses the following 2 switches:
-tUSER.NAME - USER.NAME is defined by usernames in my server
-mMESSAGE - Is the Message to be sent.

Now.. MESSAGE can be longer by using ""'s so if I wanted to send a message to myself, on a command line I would enter:
cmdmsgr.exe -tEkholm.Rod -m"This is a test Message. I want to get it all."
My pager would receive "This is a test Message. I want to get it all."
The problem is, when I define my variable, whick might look like 4972 page sent 08:46:13a 4 12BA 0,000AN p3 1991277 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL). Idealy when this program sees 4972, it would take the last part of this text, which is the actual message, and send it to the variable. Then I would like to be able to pass the ENTIRE variable to the command line.
Someone before said if the message always had the tilde in it... But it doesn't. However.. the 36 right before this example message, is the amount of the characters that are in the message. So counting them should be fairly easy, if I knew how. I know it can be done.
Back to top
View user's profile Send private message Yahoo Messenger
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed May 23, 2007 2:39 am    Post subject: Reply with quote

Code:

list create,1
list loadtext,1
"4954 page sent 08:46:13a 4 12BA 0,000AN p3 1991277 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
"4976 page sent 08:46:14a 4 12BA 0,000AN p3 1991316 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
"4978 page sent 08:46:14a 4 12BA 0,000AN p3 1991588 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
"4972 page sent 08:46:15a 4 12BA 0,000AN p3 1991284 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
"4920 page sent 08:46:15a 4 12BA 0,000AN p3 1991285 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
"4981 page sent 08:46:15a 2 12BA 0,000AN p3 1991564 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
"4952 page sent 08:46:16a 4 12BA 0,000AN p3 1991261 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
"4474 page sent 08:46:16a 4 12BA 0,000AN p3 1991192 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)
REM The text read in from the pager file:
%%ret = @match(1,"4972")
%%text = @item(1)
if @greater(@len(%%text),0)
  %%len = @len(%%text)
  REM Get the amount of characters in the message.
  %%count = @substr(%%text,54,55)
  REM Find the beginning of the message.
  %%start = @succ(@fsub(%%len,%%count))
  %%msg = @substr(%%text,%%start,%%len)
  info Command-line: @chr(34)%%msg@chr(34)
  REM RUN cmdmsgr.exe -tEkholm.Rod -m@chr(34)%%msg@chr(34)
else
  warn No match found.
end
exit

Instead of using 'loadtext' use 'loadfile' of course.
Still seems like overkill as it looks like the message always starts at character 57. So you just need @substr(%%text,57,@len(%%text))
If the message doesn't always start at the 57th char, then show us an example of that.

_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Wed May 23, 2007 2:51 am    Post subject: Reply with quote

How about this:

Code:
  %%text = "4972 page sent 08:46:13a 4 12BA 0,000AN p3 1991277 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)"

  %%len = @len(%%text)
  %%countpoint = @diff(%%len,4)
  repeat
    %x = @substr(%%text,%%countpoint,@sum(%%countpoint,2))
    %%countpoint = @pred(%%countpoint)
  until @equal(" D ",%x) @equal(0,%%countpoint)
  %%Message = @substr(%%text,@sum(%%countpoint,7),%%len)
  info %%Message
  stop

_________________
cheers

Dave
Back to top
View user's profile Send private message
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Wed May 23, 2007 3:03 am    Post subject: Reply with quote

SnarlingSheep wrote:
Still seems like overkill as it looks like the message always starts at character 57. So you just need @substr(%%text,57,@len(%%text))
If the message doesn't always start at the 57th char, then show us an example of that.

Yep, overkill. If the message always starts at the 57th character the following would do:

Code:
  %%msg = @substr(%%text,57,@len(%%text))

_________________
cheers

Dave
Back to top
View user's profile Send private message
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Wed May 23, 2007 2:26 pm    Post subject: Reply with quote

Hmm, I was just thinking about the maximum length of a text message. SMS messages usually have a maximum character length of 160. If your pager has a message length longer than 99 characters does it appear as:

4972 page sent 08:46:13a 4 12BA 0,000AN p3 1991277 D 100 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)

or:

4972 page sent 08:46:13a 4 12BA 0,000AN p3 1991277 D100 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)

If the latter you'd need to change my previous example code to:

Code:
  %%text = "4972 page sent 08:46:13a 4 12BA 0,000AN p3 1991277 D 36 ~CANCEL E44 - DIST 9 TO HANDLE (LNL)"

  %%len = @len(%%text)
  %%countpoint = @diff(%%len,4)
  repeat
    %x = @substr(%%text,%%countpoint,@sum(%%countpoint,2))
    %%countpoint = @pred(%%countpoint)
  until @equal(" D ",%x) @equal(" D1",%x) @equal(0,%%countpoint)
  %%Message = @substr(%%text,@sum(%%countpoint,7),%%len)
  info %%Message
  stop

_________________
cheers

Dave
Back to top
View user's profile Send private message
kc7aad
Contributor
Contributor


Joined: 09 Oct 2005
Posts: 53
Location: Spokane Washington

PostPosted: Wed May 23, 2007 3:32 pm    Post subject: Reply with quote

It is the later example... D100 Here's another question... Would it be better or a smarter way to PARSE the line, rather than just try and send the whole thing? The advantage then, is I would only be getting the relivant part of the message. And since I plan on trying to use this on a multi-person level, I knw they would not need to know anything more than just the message part.

As for your exaple Dave, So when I run it, I get the info message and that's fine.. I can convert the info into a run command and **should** be able to make it work. But what do I need to do to make it point to my .TXT file, rather than just the one liner example?


Unfortunatly this is proving to me to be a bit more than I bargained for!! But I figure if I keep stumbling on it, eventually I will learn to walk!!
Back to top
View user's profile Send private message Yahoo Messenger
SnarlingSheep
Professional Member
Professional Member


Joined: 13 Mar 2001
Posts: 759
Location: Michigan

PostPosted: Wed May 23, 2007 4:02 pm    Post subject: Reply with quote

Check my first example, it loads the text in from a file.
_________________
-Sheep
My pockets hurt...
Back to top
View user's profile Send private message Send e-mail
DaveR
Valued Contributor
Valued Contributor


Joined: 03 Sep 2005
Posts: 413
Location: Australia

PostPosted: Thu May 24, 2007 3:27 am    Post subject: Reply with quote

kc7aad wrote:
Unfortunatly this is proving to me to be a bit more than I bargained for!! But I figure if I keep stumbling on it, eventually I will learn to walk!!

It's actually quite easy. SS and I have provided enough info for you to achieve what you need.

If the pager numbers are always 4 digits, and you want to send every message in the file, use the following (replace 'page.txt' with the full path to your file):

Code:
  list create,1
  list loadfile,1,page.txt
  if @greater(@count(1),0)
    list seek,1,0
    while @ok()
      if @item(1)
        %%text = @item(1)
        %%pager = @substr(%%text,1,4)
        %%len = @len(%%text)
        %%countpoint = @diff(%%len,4)
        repeat
          %x = @substr(%%text,%%countpoint,@sum(%%countpoint,2))
          %%countpoint = @pred(%%countpoint)
        until @equal(" D ",%x) @equal(" D1",%x) @equal(0,%%countpoint)
        %%Message = @substr(%%text,@sum(%%countpoint,7),%%len)
        # Put code here to send message
        # Using info for debugging
        info Pager is %%pager@cr()Message is %%message
      end
      %x = @next(1)
    wend
  end
  list close,1
  exit

_________________
cheers

Dave
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group