12-10-2008
Perl - if conditions is meet, push the last field of $_ into an array
I am using a seed file shown below to separate cisco devices by ios/os type. I want to bunch all the devices based on ios/os version. Once I find a match, I only want to push the ip address into the appropriate array.
Example of seedfile
8 host1 (C3500XL-C3H2S-M) 11.0(5)WC17 10.1.44.21
9 host2 (C3500XL-C3H2S-M) 12.0(5)WC17 10.1.44.22
10 host3 (C3500XL-C3H2S-M) 12.0(5)WC17 10.1.44.23
11 host4 (cat4000-I9K91S-M) 12.2(25)EWA2 10.1.1.20
12 host5 (cat4000-I9K91S-M) 12.2(25)EWA2 10.1.1.21
13 host6 (cat4000-I9K91S-M) 12.2(25)EWA2 10.1.1.22
14 host7 (cat4000-I9K91S-M) 12.2(25)EWA2 10.1.1.23
15 host8 (cat4000-I9K91S-M) 12.2(25)EWA2 10.1.1.24
16 host9 (cat4000-I9K91S-M) 12.2(25)EWA2 10.1.1.25
17 host10 (cat4000-I9K91S-M) 12.2(25)EWA2 10.1.1.26
18 host11 (cat4000-I9K91S-M) 11.2(25)EWA6 10.1.1.27
19 host12 (cat4000-I9K91S-M) 12.2(25)EWA6 10.1.1.28
20 host13 (cat4000-I9K91S-M) 12.2(25)EWA2 10.1.1.29
21 host14 (C3550-I5Q3L2-M) 12.1(22)EA4 10.1.44.5
22 host15 WS-C6506 7.6(8) 10.1.48.10
open (INFILE, "seedfile") or die;
while (<INFILE>) {
chomp($_);
if ($_ =~ /\s\b[5-9]\./) {push(@dos, $_)};
if ($_ =~ /\s\b11\./) {push(@d110, $_)};
if ($_ =~ /\s\b12\.0/) {push(@d120, $_)};
if ($_ =~ /\s\b12\.1/) {push(@d121, $_)};
}
#test to make sure I know whats in "thar"
for ($lindex = 0; $lindex <= $#dos; $lindex++) {
print $dos[$lindex] . "\n";
}
close INFILE;
if $_ meets the requirements, I only want to push the ip address into the "d" arrays. $_[4] <- This obviously doesnt work, but illustrates what it is I want to parse.
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
hi,
another perl question,
I don't understand the below
while (<FILE>) {
push @last5, $_; #add to the end
shift @last5 if @last5 > 5 ; #take from the beginning
}
can someone please explain to me how does
shift @last5 if @last5 > 5 is taking last 5 lines from... (5 Replies)
Discussion started by: hankooknara
5 Replies
2. Shell Programming and Scripting
$key = "a";
$value = "hello";
%myhash = {} ;
push @{ myHash{$key} }, $hello;
print $myHash{$key}."\n";
this script prints
"hello" but has following error message.
Reference found where even-sized list expected at ./test line 5.
can any one help me to fix this problem?? (3 Replies)
Discussion started by: bonosungho
3 Replies
3. Shell Programming and Scripting
NEWBIE ALERT!
Hi,
I'm 1 month into learning Perl and done reading "Minimal Perl" by Tim Maher (which I enjoyed enoumously). I'm not a programmer by profession but want to use Perl to automate various tasks at my job. I have a problem (obviously) and are looking for your much appreciated help.... (0 Replies)
Discussion started by: jospan
0 Replies
4. Shell Programming and Scripting
Hi Everyone,
Any simple code can simplify the code below, please advice. Thanks
# cat 2.pl
#!/usr/bin/perl
use warnings;
use strict;
my @aaaaa = <DATA>;
my @uids;
foreach (@aaaaa) {
my @ccccc = split (",", $_);
push @uids, $ccccc;... (3 Replies)
Discussion started by: jimmy_y
3 Replies
5. Shell Programming and Scripting
Hi Everyone,
#!/usr/bin/perl
use strict;
use warnings;
my @test=("a;b;qqq;c;d","a;b;ggg;c;d","a;b;qqq;c;d");
would like to split the @test array into two array:
@test1=(("a;b;qqq;c;d","a;b;qqq;c;d"); and @test2=("a;b;ggg;c;d");
means search for 3rd filed.
Thanks
find the... (0 Replies)
Discussion started by: jimmy_y
0 Replies
6. Shell Programming and Scripting
Hi Everyone,
($total+=$_) for @record;
assume @record=(1,2,3), so the result is 6.
if @record=("1 3","2 3","3 3"), would like to sum up the 2nd field of this array, the result is 9.
i tried " ($total+=$) for @record ", cannot, please advice.
Thanks
---------- Post updated at 03:45... (1 Reply)
Discussion started by: jimmy_y
1 Replies
7. Shell Programming and Scripting
Hi ,
I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code.
my $current_value=12345;
my @users=("bob","ben","tom","harry");
open DBLIST,"<","/var/tmp/DBinfo";
my @input = <DBLIST>;
foreach (@users)
{
my... (11 Replies)
Discussion started by: chidori
11 Replies
8. Programming
I have a code snippet here that is supposed to vary values of certain parameter values:
<script type="text/javascript">
// dynamic array of which its ultimate size is unknown
// an array of arrays, each consisting of one variation
var variations = ;
// parameters of how to create a... (0 Replies)
Discussion started by: figaro
0 Replies
9. Shell Programming and Scripting
In the awk below I am trying to print only the header lines starting with # or ## and the lines that $7 is PASS and AF= is less than 5%. The awk does execute but returns an empty file and I am not sure what I am doing wrong. Thank you.
file
... (0 Replies)
Discussion started by: cmccabe
0 Replies
10. Shell Programming and Scripting
I am trying to use awk to print lines that satisfy either of the two conditions below:
condition 1: $2 equals CNV and the split of $3, the value in red, is greater than or equal to 4. ---- this is a or so I think
condition 2: $2 equals CNV and the split of $3, the value in red --- this is a... (4 Replies)
Discussion started by: cmccabe
4 Replies
LEARN ABOUT DEBIAN
smd-loop
smd-loop(1) Sync Mail Dir (smd) documentation smd-loop(1)
NAME
smd-loop - iterates smd-pull and smd-push
SYNOPSIS
smd-loop [-vt]
DESCRIPTION
smd-loop runs smd-push and smd-pull at regular intervals as defined by the user in the ~/.smd/loop configuration file. On errors that are
reported to be transient, it retries a second time before failing.
The configuration file is line-oriented. Each line is composed of three space separated fields: pull-frequency, push-frequency and end-
point-name. Frequencies are expressed in minutes, while endpoint name is a valid name for smd-pull(1) and smd-push(1). Lines beginning with
# are considered as comments. The following example calls the command smd-pull default every 3 minutes, and smd-push default every 10.
Example:
# pull-frequency push-frequency endpoint-name
3 10 default
OPTIONS
-v Increase program verbosity (printed on stderr)
-t Just create a template configuration file if none
FILES
~/.smd/loop
SEE ALSO
mddiff(1), smd-server(1), smd-client(1), smd-push(1), smd-pull(1)
AUTHOR
Enrico Tassi <gares@fettunta.org>
11 June 2012 smd-loop(1)