LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-28-2008, 01:01 AM   #1
nik1984
LQ Newbie
 
Registered: Sep 2007
Posts: 7

Rep: Reputation: 0
Using regular expression in expect script


using regular expression in expect scripts

i wrote expect script that will check string out put of "show clock" command but i want to validate this using regular expression...how i can do validation using expect script & store output from expect command.

==================================
sample expect script


#!/usr/bin/expect -f

set timeout -1
spawn ./Nikcli.sh
expect -exact "\rNik> [m"
set date_var [exec date]

send -- "show clock\r"
expect -exact "$date_var\r
\rNik> "

send -- ""
expect eof

=============================


-Thanks in advance
 
Old 08-28-2008, 06:25 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
Use the -indices flag to the expect command, and the -re pattern type option. Then the expect_out variable will be set after a match is found, and sub-expressions in your RE will be available.

From the expect manual page:
Quote:
If a process produced the output "abbbcabkkkka\n", the result of:
Code:
expect -indices -re "b(b*).*(k+)"
is as if the following statements had executed:
Code:
set expect_out(0,start) 1
set expect_out(0,end) 10
set expect_out(0,string) bbbcabkkkk
set expect_out(1,start) 2
set expect_out(1,end) 3
set expect_out(1,string) bb
set expect_out(2,start) 10
set expect_out(2,end) 10
set expect_out(2,string) k
set expect_out(buffer) abbbcabkkkk
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression Ammad Linux - General 5 08-01-2008 07:41 AM
Regular Expression harkonen Programming 6 07-12-2008 12:06 PM
Need help with a regular expression abefroman Programming 2 05-28-2008 09:17 PM
Regular expression datbenik Programming 1 01-05-2006 01:58 PM
Need help with Regular Expression subaruwrx Linux - Newbie 6 09-04-2004 07:48 PM


All times are GMT -5. The time now is 03:18 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration