Home   Archive   Permalink



Parsing to maybe the end of the line

Once again I am vexed by 'parse' and wondering if anyone can point me in the right direction.
    
I am trying to parse a log file. Naturally the company that produces the log file does not make it easy. I have lines that can look like these two examples:
    
Configured from console by jsmith on vty0 (10.1.250.78)
Configured from memory by console
    
The two items I want to pull out are the user ID ('jsmith' on the first line and 'console' on the second), and the IP address between the parentheses (present on the first line only).
    
I have been using the following code, which works on the first line because there is something following the user ID:
    
parse/case WS-MSG [
     thru ' by ' copy WS-USERID TO ' '
     thru '(' copy WS-FROM TO ')'
]
    
It works on the first line because I can parse to the space following the user ID. On the second line, it doesn't work, probably because there is no space after the word 'console' because the line ends there.
    
So what I want to do is parse through the string ' by ' and then pick up whatever follows that up to EITHER the next space OR the end of the line. That's the part I don't know how to code: Up to EITHER the next space OR the end of the line.    
    
With all that 'parse' can do I can't believe it can't do that, so I wonder if someone could explain.
    
Thank you. (Yes, I am reading manual but it is a bit confusing for me.)
    


posted by:   Steven White     12-May-2017/11:53:54-7:00



Some options: you could split by space and block parse the line:
    
     line: parse/all line " "
     parse line ["Configured" "from" set userid to string! "by" set from string! to end]
    
If the user id always conforms to a set of alpha characters, you can use charsets to parse:
    
     id-char: charset [#"a" - #"z"]
     parse/all/case line ["Configured from " copy userid some id-char " by " copy from some id-char to end]


posted by:   Chris     12-May-2017/12:27:58-7:00