LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-07-2006, 03:28 AM   #1
dav_y2k
LQ Newbie
 
Registered: Apr 2005
Distribution: RedHat
Posts: 16

Rep: Reputation: 0
Parsing rows and column data from a file using perl


Hi all,
I am a newbie to perl and have successfully added the information below from multiple devices and interfaces (using the "show queueing int interface" command) into multiple files and split the info from each file into an array,

I need to be able to parse the data in such a way that I can pick any of the corresponding info. from any column to its corresponding row. e.g if I want to add the total no. of drops or thresh etc. or I want to match any of the [cos-map] row to its corresponding queue or thresh.


Packets dropped on Transmit:
BPDU packets: 0

queue thresh dropped [cos-map]
---------------------------------------------------
1 1 0 []
1 2 0 []
2 1 1766 [0 1 2 3 4 5 6 7 ]
2 2 0 []


thanks
 
Old 10-08-2006, 11:57 AM   #2
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Is this anything at all like you have in mind?
Code:
#!/usr/bin/perl -w
# Example: ./myscript 4
# queue thresh dropped [cos-map]

my $COS = $ARGV[0];
print "\n";

open(INFILE, "/home/file.txt") || die "Can't open file for read: $!";
while (<INFILE>){
   ($var1, $var2, $var3) = split /\s+/;

   $QT = ($QT += $var1);
   $TT = ($TT += $var2);
   $DT = ($DT += $var3);
   write;
}

# Note: leave the periods ( . ) as they are needed.

# Output text header
format STDOUT_TOP =
  queue    thresh   dropped    [cos-map]

.

# Output text body
format STDOUT =
@#####  @#####    @#####     @#####
$var1,$var2,$var3,$COS
.

$~ = "STDOUT_TOTALS";
write;

# Output text footer
format STDOUT_TOTALS =
-------------------------------------
@#####  @#####    @#####
$QT,$TT,$DT

.
####End
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert 1 column into several rows in Linux? markraem Linux - Software 9 03-30-2010 11:24 AM
text data conversion: rows into columns frankie_DJ Programming 6 06-03-2006 06:43 AM
Parsing large text file with perl smaida Programming 5 09-13-2004 04:33 AM
Perl Sqlite DBI $sth->rows The Jesus Programming 0 10-21-2003 11:35 PM
perl - writing a data structure to a file.. is it possible? paavaka Programming 4 07-14-2001 12:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration