Go Job Hunting at the LQ Job Marketplace
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 10-07-2006, 04:28 AM   #1
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 []

Old 10-08-2006, 12:57 PM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 58
Is this anything at all like you have in mind?
#!/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);

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

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


# Output text body
format STDOUT =
@#####  @#####    @#####     @#####


# Output text footer
@#####  @#####    @#####



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:24 PM
text data conversion: rows into columns frankie_DJ Programming 6 06-03-2006 07:43 AM
Parsing large text file with perl smaida Programming 5 09-13-2004 05:33 AM
Perl Sqlite DBI $sth->rows The Jesus Programming 0 10-22-2003 12:35 AM
perl - writing a data structure to a file.. is it possible? paavaka Programming 4 07-14-2001 01:04 AM

All times are GMT -5. The time now is 01:10 PM.

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