Solved

Dirty Data and Errors

Posted on 2013-11-01
2
179 Views
Last Modified: 2013-11-01
I want to scan a log file for bad connections, looking in column #3, and #6 only. I only want to print lines that have a numerical value of greater than say 250. Some of the columns might have non-numerical values in them. They should not be included.

I have included output below. I would only want the line starting with "name1" to be printed. The value to be over 250 could be either #3, or #6.

Router   Interface     ---ES--  --SES--  --SEFS-  --UAS--  --CSS--  --PCV--  --LES--  --BES--  -TotVal-
name1 T1_0/0/0       389        9       43       38        0     3110        0      279       96
name2 T1_0/0/0         0        0        0        0        0        0        0        0       96
name3 T1_0/0/1         0        0        0        0        0        0        0        0       96
name4 T1_0/1/0         0        0        0        0        0        0        0        0       96
0
Comment
Question by:stakor
2 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
Comment Utility
perl -ane 'print if $F[2]>250 || $F[6]>250' file.log
0
 
LVL 26

Assisted Solution

by:wilcoxon
wilcoxon earned 250 total points
Comment Utility
Try this...
#!/usr/local/bin/perl
use strict;
use warnings;
my $fil = shift or die "Usage: $0 logfile\n";
open IN, $fil or die "could not open $fil: $!";
while (<IN>) {
    next if /^\s*Router\s*Interface\b/; # skip header row
    my @cols = split;
    print if ($cols[2] > 250 or $cols[5] > 250); # perl is 0-based so this is cols 3 and 6
}
close IN;

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now