[ale] Extracting a second line

Christopher Fowler cfowler at outpostsentinel.com
Fri May 6 20:02:47 EDT 2005


I'm using regular expressions to extract some data fromt he following
text

> Code: 400 Time: 23:51:04 UTC 05-MAY-2005 SN: 00824 Version: 1.42
  Promedica Bixby Medical Center - 818 Riverside Avenue Adrian Mi

I use Expect on the file handle to check for that data.

$location_regex = "Code: 400
([[:print:]])*([[:cntrl:]])+([[:print:]])*([[:cntrl:]])+";
push @triggers, cook_regex(undef, $location_regex, "LOCATION");


Here is execution of expect:
my (undef, $error) = $exp->expect(0, @triggers);

So if Expect sees two lines of data that starts with 'Code: 400' Then
self->match will have the text that caused the match.

Output:
[cfowler at ze1250 gk]$  sudo  ./gk.pl -p /dev/ttyS1 -o DEMO -v -D 3 -f SH
05-06 12:02:27 Initilizing Modem.
05-06 12:02:27 Modem initialized.
05-06 12:02:33 Incoming call. Answering..
05-06 12:02:44 Call answered.
05-06 12:02:47 Found: Code: 400 Time: 23:51:04 UTC 05-MAY-2005 SN: 00824
Version: 1.42
05-06 12:02:47   Promedica Bixby Medical Center - 818 Riverside Avenue
Adrian Mi
05-06 12:02:47 Location information received.
05-06 12:02:55 Call Terminated.
05-06 12:02:56 Initilizing Modem.
05-06 12:02:56 Modem initialized.


I need to somehow extract the location information from the second line.
I know that it has leading spaces.  I want all the text after the
leading spaces.  I do not know if the first lines ends in '\n','\m' or
'\r\n' so that is why in the POSIX regex I used ([[:cntrl:]])+ to detect
the end of the first and second lines so I can get them both.

Can someone tell me that if I have a string that looks like this

"Code: 400 Time: 23:51:04 UTC 05-MAY-2005 SN: 00824 Version: 1.42
  Promedica Bixby Medical Center - 818 Riverside Avenue Adrian Mi"

and based on the knows above how I can extract all the data past the
leading spaces on the second line?  Also is there a better regex I can
use for Expect?

Thanks,
Chris 





More information about the Ale mailing list