Sponsored Content
Top Forums Shell Programming and Scripting Perl Regular Expression Word Search Post 302362924 by xmaverick on Sunday 18th of October 2009 07:51:31 PM
Old 10-18-2009
Perl Regular Expression Word Search

I'm trying to have my perl script telnet into the network device execute a command then dump the output of the command into a variable. The script then greps for the word "STANDBY". I can't seem to get the script to print out the output because it seems that the script can't find the word "STANDBY". I believe this is because i'm not using good regular expression.

#!/usr/bin/perl -w 
use strict; 
use warnings; 
use Net::Telnet; 
my $ip = $ARGV[0]; 
my $pass = "mgcusr"; 
my $pass2 = "S3attl3"; 
my $t=new Net::Telnet(Errmode=>'return',Input_Log => "/tmp/input.log",Timeout=>30); 
 if($t->errmsg) { my $err=$t->errmsg; return $err; } 
 my ($prompt) = $t->waitfor('/login: $/'); 
    if($t->errmsg) { my $err=$t->errmsg; return $err; } 
    my @out=$t->cmd(String=>'rtrv-ne',Prompt=>'/>$/'); 
    my @matches = grep {/[A-Z]BY/} @out;  
    my $line = $matches[0] if @matches or die "can't find parameters specified"; 
    print "$line\n" Image


10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

regular expression for replacing the fist word with a last word in line

I have a File with the below contents File1 I have no prior experience in unix. I have just started to work in unix. My experience in unix is 0. My Total It exp is 3 yrs. I need to replace the first word in each line with the last word for example unix have no prior experience in... (2 Replies)
Discussion started by: kri_swami
2 Replies

2. Shell Programming and Scripting

awk + pattern search with regular expression

Hi , I have a file with "|" (pipe) as a delimeter. I am looking for the record count where 5th field is a number with 15 digit length only. all the records with above requirement is valid rest all are invalid. I need count of valid records and invalid records. Can anyone please help (9 Replies)
Discussion started by: vikash_k
9 Replies

3. Shell Programming and Scripting

How to delete the word after a regular expression

Example: Lucas RUNCYCLE Rule1 Astigmatism Robot RUNCYCLE Rule2 Jack RUNCYCLE Calendar1 June Lucy RUNCYCLE Exception4 Fear RUNCYCLE Calendar5 August In this example, how can I delete the next after the expression RUNCYCLE? (i.e. Rule1, Rule2, Calendar1, Exception1, Calendar5) I'm... (3 Replies)
Discussion started by: The Gamemaster
3 Replies

4. Shell Programming and Scripting

search a regular expression and match in two (or more files) using bash

Dear all, I have a specific problem that I don't quite understand how to solve. I have two files, both of the same format: XXXXXX_FIND1 bla bla bla bla bla bla bla bla bla bla bla bla ======== (return) XXXXXX_FIND2 bla bla bla bla bla bla (10 Replies)
Discussion started by: TheTransporter
10 Replies

5. Shell Programming and Scripting

Hidden Characters in Regular Expression Matching Perl - Perl Newbie

I am completely new to perl programming. My father is helping me learn said programming language. However, I am stuck on one of the assignments he has given me, and I can't find very much help with it via google, either because I have a tiny attention span, or because I can be very very dense. ... (4 Replies)
Discussion started by: kittyluva2
4 Replies

6. Shell Programming and Scripting

How can awk search a string without using regular expression?

Hello, Awk seem treat the pattern as regular expression, how can awk search not using regular expression? e.g. just represent for "", not "A" or "a" . I don't want to add backslash . (2 Replies)
Discussion started by: 915086731
2 Replies

7. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

8. Shell Programming and Scripting

Perl regular expression

Hi , I have the below array my @actionText = ("delivered to governor on 21/23/3345" , "deliver jllj" , "ram 2345/43"); When i am trying to grep the contents of array and if mathced substituting with the digitis or some date format from the element like below my @action = grep { $_ =~... (7 Replies)
Discussion started by: ragilla
7 Replies

9. Shell Programming and Scripting

Pattern search (regular expression in UNIX)

Hello , Could anyone help me to define the string in regular expression way . Below is my string \rtf1\ansi\deff0{\fonttbl{\f0\fswiss Helv;}{\f1\fnil MS Sans Serif;}} {\colortbl ;\red0\green0\blue0;} \viewkind4\uc1\pard\cf1\lang1033\f0\fs16 The string will always start as \rtf1 and... (6 Replies)
Discussion started by: Pratik4891
6 Replies

10. Shell Programming and Scripting

awk regular expression search

Hi All, I would like to search a regular expression by passing as an i/p variableto AWK. For Example :: (7 Replies)
Discussion started by: Girish19
7 Replies

Apache2::Command - Perl API for accessing Apache module command information Synopsis use Apache2::Module (); use Apache2::Command (); my $module = Apache2::Module::find_linked_module('mod_perl.c'); for (my $cmd = $module->cmds; $cmd; $cmd = $cmd->next) { $cmd->args_how(); $cmd->errmsg(); $cmd->name(); $cmd->req_override(); } Description "Apache2::Command" provides the Perl API for accessing Apache module command information API
"Apache2::Command" provides the following functions and/or methods: "args_how" What the command expects as arguments: $how = $cmd->args_how(); obj: $cmd ( "Apache2::Command object" ) ret: $how ( "Apache2::Const :cmd_how constant" ) The flag value representing the type of this command (i.e. "Apache2::Const::ITERATE", "Apache2::Const::TAKE2"). since: 2.0.00 "errmsg" Get usage message for that command, in case of syntax errors: $error = $cmd->errmsg(); obj: $cmd ( "Apache2::Command object" ) ret: $error ( string ) The error message since: 2.0.00 "name" Get the name of this command: $name = $cmd->name(); obj: $cmd ( "Apache2::Command object" ) ret: $name ( string ) The command name since: 2.0.00 "next" Get the next command in the chain of commands for this module: $next = $cmd->next(); obj: $cmd ( "Apache2::Command object" ) ret: $next ( "Apache2::Command object" ) Returns the next command in the chain for this module, "undef" for the last command. since: 2.0.00 "req_override" What overrides need to be allowed to enable this command: $override = $cmd->req_override obj: $cmd ( "Apache2::Command object" ) ret: $override ( "Apache2::Const :override constant" ) The bit mask representing the overrides this command is allowed in (i.e "Apache2::Const::OR_ALL"/"Apache2::Const::ACCESS_CONF"). since: 2.0.00 For example: use Apache2::Const -compile => qw(:override); $cmd->req_override() & Apache2::Const::OR_AUTHCFG; $cmd->req_override() & Apache2::Const::OR_LIMIT; See Also mod_perl 2.0 documentation. Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. Authors The mod_perl development team and numerous contributors. perl v5.18.2 2install::TempContent::Objects::mod_perl-2.0.9::docs::api::Apache2::Command(3)

Featured Tech Videos

All times are GMT -4. The time now is 07:39 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy