Well, you came to the right place. ;-)

Perl is excellent at doing this kind of stuff. I have written the following script that does what you wanted. (I could write a perl one-liner-ish that does the job, but I felt a complete program is probably more useful to you as 1) a tutorial on file I/O, command-line parsing. 2) a fully working utility.)

#!/use/local/bin/perl -w use strict; use IO::File; use Getopt::Long; # Parse command line arguments and assign corresponding variables GetOptions ( 'i|input=s' => \( my $INPUT = undef ), 'o|output=s' => \( my $OUTPUT = "./data-in,./data-out" ), 'g|graph=s' => \( my $GRAPH = "./graph" ), ); unless ( defined $INPUT ) { print <<USAGE SNMP data parser Usage: $0 [option] Options: -i|--input [filename] SNMP router data file -o|--output [in,out] Optional. Default is "datain,dataout". -g|--graph [command] Optional. Default is "./graph" USAGE ; exit(1); } # get the names of the datain and dataout files # note that you can override these names from # the command-line my ($datain,$dataout) = split /,\s*/, $OUTPUT; my $f = new IO::File $INPUT, "r" or die "Could not open input file $INPUT"; my $di = new IO::File $datain, "w" or die "Could not create output file $datain"; my $do = new IO::File $dataout, "w" or die "Could not create output file $dataout"; while (<$f>) { # for each line in the input file next if /^\s*$/; # ignore empty lines my @col = split /,\s+/; # split on , followed by spaces my ($date) = $col[0] =~ /^"(.*)\s.*"$/; # want date only print $di "$date, $col[2]\n"; print $do "$date, $col[3]\n"; } undef $di; # force close of files undef $do; undef $f; # do the graph system($GRAPH) or die "Could not execute $GRAPH"; exit(0); __END__ example: ./script.pl -i snmp.log
And the output from sample data are -
data-in ------- 23/10/2003, 1.86 23/10/2003, 2.26 23/10/2003, 0.74 23/10/2003, 1.15 23/10/2003, 1.61 23/10/2003, 1.55 23/10/2003, 1.11 data-out -------- 23/10/2003, 1.91 23/10/2003, 1.53 23/10/2003, 0.46 23/10/2003, 1.53 23/10/2003, 0.72 23/10/2003, 1.08 23/10/2003, 0.52

In reply to Re: modifying script to ask for file name as input by Roger
in thread modifying script to ask for file name as input by gabjones

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.