Sponsored Content
Top Forums Shell Programming and Scripting EXPECT: Assign variable by reading a line of text from a file Post 302717097 by DGPickett on Wednesday 17th of October 2012 02:14:49 PM
Old 10-17-2012
Expect is for interactive keyboard driven tools with no batch or script-friendly command line mode. If you make an expect script that works with one mac address, you could write a normal bash/ksh script to read the mac addresses, gen an expect script with that mac address embedded and run it. Expect is written in tk/tcl, as I recall, so you need skills in that arcane area to vary the script dynamically. I mostly write my expect scripts using autoexpect, or fake it using shell scripts reading the output file to determine progress. Are you going to windows autokey using telnet?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

reading the whole line from a file into a variable

Hi, I am doing : while read line do printf "%s\n" ${line} done <datafile.txt but I am not getting each single line from the data file assigned to the variable line (but only tokens/fields at a time). I also tried while IFS= read -r lineI want the whole line assigned or read into the... (2 Replies)
Discussion started by: shri_nath
2 Replies

2. Shell Programming and Scripting

Perl:Read single value from text file and assign to variable

Hello All, A part of my very basic perl code requires me to read a single value from a text file. The file output is the following: Reading image ... done IMAGEREGION=0x0x0-256x162x256 VOXELDIMENSION=0.9375000000x1.2000000477x0.9375000000 VOXELNUMBER=10527001... (7 Replies)
Discussion started by: ncl
7 Replies

3. Shell Programming and Scripting

reading line by line from a text file

Hi, I have a text file something like this: 10.10.10.1, ldap, cn=users,dc=example,dc=com ..... ... and many more lines ... ... now i want to read each individual line from the file and assign it to a variable example: the script should read 10.10.10.1 and assign it to a variable say... (3 Replies)
Discussion started by: sunrexstar
3 Replies

4. Fedora

How to read a text file and assign the values in the same to a variable in loop

Hi, I have a text file with multiple lines, each having data in the below format <DOB>,<ADDRESS> I have to write a script which reads each line in the text file in loop, assign the values to these variables and do some further processing in it. Using the following code prints the... (1 Reply)
Discussion started by: manishab00
1 Replies

5. UNIX for Advanced & Expert Users

How to read a text file and assign the values in the same to a variable in loop

Hi, I have a text file with multiple lines, each having data in the below format <DOB>,<ADDRESS> I have to write a script which reads each line in the text file in loop, assign the values to these variables and do some further processing in it. Using the following code prints the values... (12 Replies)
Discussion started by: manishab00
12 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

Reading text file, comparing a value in a line, and placing only part of the line in a variable?

I need some help. I would like to read in a text file. Take a variable such as ROW-D-01, compare it to what's in one line in the text file such as PROD/VM/ROW-D-01 and only input PROD/VM into a variable without the /ROW-D-01. Is this possible? any help is appreciated. (2 Replies)
Discussion started by: xChristopher
2 Replies

8. UNIX for Dummies Questions & Answers

Assign line from file to variable

Hi, I am new to shell scripting. Need help with the below requirement. I need help to read a log file and line containing word ORA needs to be captured into a variable and the values of the variable need to be inserted into a table. For E.g. file test.sql has below error: ORA-01017:... (3 Replies)
Discussion started by: ricsharm
3 Replies

9. Shell Programming and Scripting

Do While Loop + Read From File + assign line to a variable

Hello, I am using below code for reading from a file and assigning the values to a variable , but it is loosing the value after the loop , please suggest to retain the value of the variable after the loop , while IFS=: read -r line do set $dsc=$line echo 'printing line variable ' $line... (1 Reply)
Discussion started by: ParthThakkar
1 Replies

10. UNIX for Dummies Questions & Answers

Reading foreach variable from a text file

Hello, I have a text file named "foreach.txt" which reads like --- foreach cal ( 1 2 3 4 5 ) I am using a simple script which looks like --- #!/bin/tcsh foreach cal (1 2 3 4 5) echo "$cal" end Is it possible to modify the script in such a way that instead of writing foreach cal (1... (6 Replies)
Discussion started by: Indra2011
6 Replies
Pod::POM::Node(3)					User Contributed Perl Documentation					 Pod::POM::Node(3)

NAME
Pod::POM::Node - base class for a POM node SYNOPSIS
package Pod::POM::Node::Over; use base qw( Pod::POM::Node ); use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR ); %ATTRIBS = ( indent => 4 ); @ACCEPT = qw( over item begin for text verbatim ); $EXPECT = q( back ); package main; my $list = Pod::POM::Node::Over->new(8); $list->add('item', 'First Item'); $list->add('item', 'Second Item'); ... DESCRIPTION
This documentation describes the inner workings of the Pod::POM::Node module and gives a brief overview of the relationship between it and its derived classes. It is intended more as a guide to the internals for interested hackers than as general user documentation. See Pod::POM for information on using the modules. This module implements a base class node which is subclassed to represent different elements within a Pod Object Model. package Pod::POM::Node::Over; use base qw( Pod::POM::Node ); The base class implements the new() constructor method to instantiate new node objects. my $list = Pod::POM::Node::Over->new(); The characteristics of a node can be specified by defining certain variables in the derived class package. The %ATTRIBS hash can be used to denote attributes that the node should accept. In the case of an "=over" node, for example, an "indent" attribute can be specified which otherwise defaults to 4. package Pod::POM::Node::Over; use base qw( Pod::POM::Node ); use vars qw( %ATTRIBS $ERROR ); %ATTRIBS = ( indent => 4 ); The new() method will now expect an argument to set the indent value, or will use 4 as the default if no argument is provided. my $list = Pod::POM::Node::Over->new(8); # indent: 8 my $list = Pod::POM::Node::Over->new( ); # indent: 4 If the default value is undefined then the argument is mandatory. package Pod::POM::Node::Head1; use base qw( Pod::POM::Node ); use vars qw( %ATTRIBS $ERROR ); %ATTRIBS = ( title => undef ); package main; my $head = Pod::POM::Node::Head1->new('My Title'); If a mandatory argument isn't provided then the constructor will return undef to indicate failure. The $ERROR variable in the derived class package is set to contain a string of the form "$type expected a $attribute". # dies with error: "head1 expected a title" my $head = Pod::POM::Node::Head1->new() || die $Pod::POM::Node::Head1::ERROR; For convenience, the error() subroutine can be called as a class method to retrieve this value. my $type = 'Pod::POM::Node::Head1'; my $head = $type->new() || die $type->error(); The @ACCEPT package variable can be used to indicate the node types that are permitted as children of a node. package Pod::POM::Node::Head1; use base qw( Pod::POM::Node ); use vars qw( %ATTRIBS @ACCEPT $ERROR ); %ATTRIBS = ( title => undef ); @ACCEPT = qw( head2 over begin for text verbatim ); The add() method can then be called against a node to add a new child node as part of its content. $head->add('over', 8); The first argument indicates the node type. The @ACCEPT list is examined to ensure that the child node type is acceptable for the parent node. If valid, the constructor for the relevant child node class is called passing any remaining arguments as attributes. The new node is then returned. my $list = $head->add('over', 8); The error() method can be called against the parent node to retrieve any constructor error generated by the child node. my $list = $head->add('over', 8); die $head->error() unless defined $list; If the child node is not acceptable to the parent then the add() method returns one of the constants IGNORE, REDUCE or REJECT, as defined in Pod::POM::Constants. These return values are used by the Pod::POM parser module to implement a simple shift/reduce parser. In the most common case, IGNORE is returned to indicate that the parent node doesn't know anything about the new child node. The parser uses this as an indication that it should back up through the parse stack until it finds a node which will accept this child node. Through this mechanism, the parser is able to implicitly terminate certain POD blocks. For example, a list item initiated by a "=item" tag will not accept another "=item" tag, but will instead return IGNORE. The parser will back out until it finds the enclosing "=over" node which will accept it. Thus, a new "=item" implicitly terminates any previous "=item". The $EXPECT package variable can be used to indicate a node type which a parent expects to terminate itself. An "=over" node, for example, should always be terminated by a matching "=back". When such a match is made, the add() method returns REDUCE to indicate successful termination. package Pod::POM::Node::Over; use base qw( Pod::POM::Node ); use vars qw( %ATTRIBS @ACCEPT $EXPECT $ERROR ); %ATTRIBS = ( indent => 4 ); @ACCEPT = qw( over item begin for text verbatim ); $EXPECT = q( back ); package main; my $list = Pod::POM::Node::Over->new(); my $item = $list->add('item'); $list->add('back'); # returns REDUCE If a child node isn't specified in the @ACCEPT list or doesn't match any $EXPECT specified then REJECT is returned. The parent node sets an internal error of the form "$type expected a terminating $expect". The parser uses this to detect missing POD tags. In nearly all cases the parser is smart enough to fix the incorrect structure and downgrades any errors to warnings. # dies with error 'over expected terminating back' ref $list->add('head1', 'My Title') # returns REJECT || die $list->error(); Each node contains a 'type' field which contains a simple string indicating the node type, e.g. 'head1', 'over', etc. The $NODES and $NAMES package variables (in the base class) reference hash arrays which map these names to and from package names (e.g. head1 <=> Pod::POM::Node::Head1). print $list->{ type }; # 'over' An AUTOLOAD method is provided to access to such internal items for those who don't like violating an object's encapsulation. print $list->type(); Nodes also contain a 'content' list, blessed into the Pod::POM::Node::Content class, which contains the content (child elements) for the node. The AUTOLOAD method returns this as a list reference or as a list of items depending on the context in which it is called. my $items = $list->content(); my @items = $list->content(); Each node also contains a content list for each individual child node type that it may accept. my @items = $list->item(); my @text = $list->text(); my @vtext = $list->verbatim(); The present() method is used to present a node through a particular view. This simply maps the node type to a method which is then called against the view object. This is known as 'double dispatch'. my $view = 'Pod::POM::View::HTML'; print $list->present($view); The method name is constructed from the node type prefixed by 'view_'. Thus the following are roughly equivalent. $list->present($view); $view->view_list($list); The benefit of the former over the latter is, of course, that the caller doesn't need to know or determine the type of the node. The node itself is in the best position to determine what type it is. AUTHOR
Andy Wardley <abw@kfs.org> COPYRIGHT
Copyright (C) 2000, 2001 Andy Wardley. All Rights Reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Consult Pod::POM for a general overview and examples of use. perl v5.16.3 2010-04-02 Pod::POM::Node(3)
All times are GMT -4. The time now is 02:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy