Sponsored Content
Top Forums Shell Programming and Scripting Expect: Parsing/evaluating lines of numbers Post 302135871 by kajkaj on Thursday 13th of September 2007 04:24:40 AM
Old 09-13-2007
Expect: Parsing/evaluating lines of numbers

There *has* to be an elegant way to do this in Expect...

I have a command that returns lines of numbers. Like:

prompt% mycommand --loop=5
9 4956 4951 4951 4956
9 4960 4951 4951 4956
9 4956 4951 4951 4956
9 4956 4951 4951 4956
9 4956 4951 4951 4956
prompt%

All numbers must be inside a given interval (eg. 4900-5000 in the case
above). If they are not I must report which column that has the number
outside the interval (column 0 above).

I could start a lot of bash and/or C programming, but I would rather
keep it all in the Expect script that I am using to invoke the command
from anyway.

Any suggestions?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Parsing Lines from a text file

Hello Guru's I know there are people who live to be able to help people like me. That's why I'm here! I have a text file that has a corresponding address information that I need to be able to get maybe as a Unix Function. The text file contains the following: AIX17_JB_C;... (3 Replies)
Discussion started by: sallender
3 Replies

2. Shell Programming and Scripting

How to remove all lines with something other than numbers

Hi, How would I get rid of lines having something else than numbers (such as tabs,white space, special characters, empty line, letters). So I have big file with numers as follows: 12345678901 23456789012 32343678901 42345638901 52345678901 and I sometimes the file might contain some... (2 Replies)
Discussion started by: Juha
2 Replies

3. Shell Programming and Scripting

expect - How to ignore empty lines?

Hi all, I'm looking for a way to generate an error when a command does not print an expected message. For example : test.sh : echo hi!test.exp : exp_internal 1 spawn ./test.sh expect { "hi!" {puts "bingo!"} "*" {puts "error!" ; exit 1} } I expected test.exp to match the string... (2 Replies)
Discussion started by: whbos
2 Replies

4. Shell Programming and Scripting

Expect: Block of lines should be executed only if access succeeds

Hello I'm using expect to create a script. I want some lines to be executed only if the telnet succeeds to the target host. Kindly check the code that i created. The problem i'm facing that while execting the script, the lines after login seems to be ignored. The password is not sent and also... (2 Replies)
Discussion started by: Hossam_Nox
2 Replies

5. Shell Programming and Scripting

print lines containing only numbers

Hi boys, I have a txt file with a lot of lines. It have lines containing mostly only numbers but some of them contain numbers mixed with special characters and or letters or space.. its look like this: 271261621371 2727127f 27126|71372. ... Do you have any ideas of the easiest way to... (3 Replies)
Discussion started by: alekkz
3 Replies

6. UNIX for Dummies Questions & Answers

Parsing file, reading each line to variable, evaluating date/time stamp of each line

So, the beginning of my script will cat & grep a file with the output directed to a new file. The data I have in this file needs to be parsed, read and evaluated. Basically, I need to identify the latest date/time stamp and then calculate whether or not it is within 15 minutes of the current... (1 Reply)
Discussion started by: hynesward
1 Replies

7. Shell Programming and Scripting

TCL expect out string with multiple lines

Hello, I will be sending this command to a specific COMID: exp_send-i $COMID "fdisk -l | grep Disk | awk '{print $2}'" The command will produce this output: /dev/sda /dev/sdb etc.. the problem is how do I store the output in a variable in TCL, I am currently using this to grab the... (1 Reply)
Discussion started by: h0ujun
1 Replies

8. Shell Programming and Scripting

Parsing expect_out using regex in expect script

Hi, I am trying to write an expect script. Being a newbie in expect, maybee this is a silly doubt but i am stuck here. So essentially , i want the o/p of one router command to be captured . Its something like this Stats Input Rx : 1234 Input Bytes : 3456 My expect script looks ... (5 Replies)
Discussion started by: ashy_g
5 Replies

9. Shell Programming and Scripting

Deleting all lines containing numbers

Hi guys I have a text file in the following format what i would like ot do is iterate through the file deleting the lines containing only numbers. I have googled this and have been unable to find any help ( maybe its my search terms) so if any one an give me a heads up i would... (3 Replies)
Discussion started by: dunryc
3 Replies

10. Shell Programming and Scripting

Print lines with numbers only.

Is there other way then this only solution I have found to print lines with numbers only? file.txtone two three 3 four five 5tt 6gfjdfgdf 9 66 six 0 seven 7 eight 546546 gffdg445gfg fd644 (7 Replies)
Discussion started by: Jotne
7 Replies
Expect::Simple(3pm)					User Contributed Perl Documentation				       Expect::Simple(3pm)

NAME
Expect::Simple - wrapper around the Expect module SYNOPSIS
use Expect::Simple; my $obj = new Expect::Simple { Cmd => [ dmcoords => 'verbose=1', "infile=$infile"], Prompt => [ -re => 'dmcoords>:s+' ], DisconnectCmd => 'q', Verbose => 0, Debug => 0, Timeout => 100 }; $obj->send( $cmd ); print $obj->before; print $obj->after; print $obj->match_str, " "; print $obj->match_idx, " "; print $obj->error_expect; print $obj->error; $expect_object = $obj->expect_handle; DESCRIPTION
"Expect::Simple" is a wrapper around the "Expect" module which should suffice for simple applications. It hides most of the "Expect" machinery; the "Expect" object is available for tweaking if need be. Generally, one starts by creating an Expect::Simple object using new. This will start up the target program, and will wait until one of the specified prompts is output by the target. At that point the caller should send() commands to the program; the results are available via the before, after, match_str, and match_idx methods. Since Expect simulates a terminal, there will be extra " " characters at the end of each line in the result (on UNIX at least). This is easily fixed: ($res = $obj->before) =~ tr/ //d; @lines = split( " ", $res ); This is not done automatically. Exceptions will be thrown on error (match with "/Expect::Simple/"). Errors from Expect are available via the error_expect method. More human readable errors are available via the error method. The connection is automatically broken (by sending the specified disconnect command to the target) when the Expect::Simple object is destroyed. Methods new $obj = Expect::Simple->new( \%attr ); This creates a new object, starting up the program with which to communicate (using the Expect spawn method) and waiting for a prompt. The passed hash reference must contain at least the Prompt, DisconnectCmd, and Cmd elements. The available attributes are: Cmd Cmd => $command, Cmd => [ $command, $arg1, $arg2, ... ], The command to which to connect. The passed command may either be a scalar or an array. Prompt This specifies one or more prompts to scan for. For a single prompt, the value may be a scalar; for more, or for matching of regular expressions, it should be an array reference. For example, Prompt => 'prompt1> ', Prompt => [ 'prompt1> ', 'prompt2> ', -re => 'promptd+>s+' ] All prompts are taken literally, unless immediately preceded by a "-re" flag, in which case they are regular expressions. DisconnectCmd This is the command to be sent to the target program which will cause it to exit. RawPty If set, then underlying Expect object's pty mode is set to raw mode (see Expect::raw_pty()). Timeout The time in seconds to wait until giving up on the target program responding. This is used during program startup and when any commands are sent to the program. It defaults to 1000 seconds. Debug The value is passed to Expect via its debug method. Verbose This results in various messages printed to the STDERR stream. If greater than 3, it turns on Expect's logging to STDOUT (via the log_stdout Expect method. send $obj->send( $cmd ); $obj->send( @cmds ); Send one or more commands to the target. After each command is sent, it waits for a prompt from the target. Only the output resulting from the last command is available via the after, before, etc. methods. match_idx This returns a unary based index indicating which prompt (in the list of prompts specified via the "Prompt" attribute to the new method) was received after the last command was sent. It will be undef if none was returned. match_str This returns the prompt which was matched after the last command was sent. before This returns the string received before the prompt. If no prompt was seen, it returns all output accumulated. This is usually what the caller wants to parse. Note that the first line will (usually) be the command that was sent to the target, because of echoing. Check this out to be sure! after This returns the 'after' string. Please read the Expect docs for more enlightenment. error This returns a cleaned up, more humanly readable version of the errors from Expect. It'll be undef if there was no error. error_expect This returns the original Expect error. expect_handle This returns the Expect object, in case further tweaking is necessary. BUGS
If the command to be run does not exist (or not in the current execution path), it's quite possible that the new method will not throw an exception. It's up to the caller to make sure that the command will run! There's no known workaround for this. LICENSE
This software is released under the GNU General Public License. You may find a copy at http://www.fsf.org/copyleft/gpl.html AUTHOR
Diab Jerius (djerius@cpan.org) perl v5.12.4 2008-05-06 Expect::Simple(3pm)
All times are GMT -4. The time now is 10:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy