Hi have a file which consist of following thing

begining of file
----------------------
my name some dfgfgfk jdksjdkls laladsl sdlsdls
.
.
.
kfdjkfdk some drt pro vhdl sdjls.
----------------------------------------------------------------
ddr.spw.df.df 0 0 0 0 0
ddr.ser.ddf.tp 1 2 3 4 1
ddr.pwq.pro.fgt.tp 1 3 4 5 7
eth.pro.iw 1 2 3 4 5
eth.3po.lk 1 2 5 6 7
eth.3yu.lo 3 4 5 6 9

--------------------------------------------------------
end of file

Now I want to seprate all lines begining with ddr and sum their 5th column, similiarly I want to seprate all lines begining with eth and sum their 5 column. The top portion of file as shown might consist of some paragraph which don't need to consider. So please can anyone help with perl script to perform this operation.

Recommended Answers

All 5 Replies

What have you tried so far? Is this school/class work?

What have you tried so far? Is this school/class work?

Hi this neither my school/class work. I don't know perl and I need this to make my work easier.

one way to do it:

my %table = (
   ddr => 0,
   eth => 0
);
open (FH, "path/to/yourfile") or die "$!"; 
while(<FH>){
   if(/^ddr\./) {
      my ($col5) = /\s(\d+)$/;
      $table{ddr}+=$col5;
   }
   elsif(/^eth\./){
      my ($col5) = /\s(\d+)$/;
      $table{eth}+=$col5;
   }
   else {
      next;
   }
}
close(FH);
print "ddr = $table{ddr}\neth = $table{eth}";

Thanks Kevin for wuick reply.
I need one more perl script to generate the following file in format given below

-----------------------

move t1
move t2
move t3
move t4
..
..
.
move tn

--------------------------

where t1, t2, t3, t4.... tn are psudo random numbers between 1 and largest 32 bit signed and unsigned number. value n can be between 1 to 40.

I need a new car myself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.