Extracting from file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting from file
# 1  
Old 04-24-2007
Extracting from file

Hi I have the file in following format

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 5th column. The top portion of file as shown might consist of some paragraph which I don't need to consider. So please can anyone help with perl script to perform this operation.

Thanks
# 2  
Old 04-24-2007
Code:
perl -ane ' if ( /^ddr/ ){ $ddr = $ddr+ $F[5]; } 
if( /^eth/ ) { $eth = $eth + $F[5]; } 
END {
	print "ddr $ddr \n" ;
	print "eth $eth\n" ;
}' file

# 3  
Old 04-24-2007
thanks for quick reply can I execute this code from a file for ex. pr.pl and then execute perl pr.pl?? Also what changes I need to made if I want to dump the result in a file??
# 4  
Old 04-24-2007
pr.pl
Code:
perl -ane ' if ( /^ddr/ ){ $ddr = $ddr+ $F[5]; } 
if( /^eth/ ) { $eth = $eth + $F[5]; } 
END {
	print "ddr $ddr \n" ;
	print "eth $eth\n" ;
}' file > outputfile

Just run with the filename pr.pl and output is sent to outputfile.
# 5  
Old 04-24-2007
Code:
awk 'BEGIN{}
	/^ddr/ { ddr += $5}
	/^eth/ { eth+=$5 }
END {
     print "ddr count is " ddr
     print "eth count is " eth
     } ' "file"

# 6  
Old 04-26-2007
Thanks for all replies. But I these code is not working for my case so I am again posting my original file for which I need to do my computation

--------------------------------------------------------------
----------------------------------------------------------------
Release 8.2i - XPower SoftwareVersion:I.31
Power summary: I(mA) P(mW)
----------------------------------------------------------------
Total estimated power consumption: 1506
---
Vccint 1.50V: 296 444
Vccaux 2.50V: 167 418
Vcco33 3.30V: 1 4
Vcco25 2.50V: 256 640
---
Clocks: 172 258
IOs: 143 434
Inputs: 2 3
Logic: 0 0
Outputs:
Vcco25 124 311
Vcco33 0 0
Signals: 0 0
---
Quiescent Vccint 1.50V: 50 75
Quiescent Vccaux 2.50V: 167 418
Quiescent Vcco33 3.30V: 1 4
Quiescent Vcco25 2.50V: 1 3
Startup Vccint 1.5V: 500
Startup Vccaux 2.5V: 250
Startup Vcco33 3.3V: 100
Startup Vcco25 2.5V: 100

Thermal summary:
----------------------------------------------------------------
Estimated junction temperature: 25C
250 LFM 25C
500 LFM 25C
750 LFM 25C
Ambient temp: 25C
Case temp: 25C
Theta J-A: 0C/W

Decoupling Network Summary: Cap Range (uF) #
----------------------------------------------------------------
Capacitor Recommendations:
Total for Vccint : 32
470.0 - 1000.0 : 1
4.70 - 10.00 : 1
0.470 - 2.200 : 3
0.0470 - 0.2200 : 6
0.0100 - 0.0470 : 10
0.0010 - 0.0047 : 11
---
Total for Vccaux : 16
470.0 - 1000.0 : 1
0.470 - 2.200 : 1
0.0470 - 0.2200 : 3
0.0100 - 0.0470 : 5
0.0010 - 0.0047 : 6
---
Total for Vref : 19
0.0470 - 0.2200 : 9
0.0100 - 0.0470 : 10
---
Total for Vcco25 : 8
470.0 - 1000.0 : 1
0.0470 - 0.2200 : 1
0.0100 - 0.0470 : 2
0.0010 - 0.0047 : 4
---
Total for Vcco33 : 8
470.0 - 1000.0 : 1
0.0470 - 0.2200 : 1
0.0100 - 0.0470 : 2
0.0010 - 0.0047 : 4

Power details:
-------------------------------------------------------------------------------
Clocks:4 Loads Loading(fF) C(pF) F(MHz) I(mA) P(mW)
-------------------------------------------------------------------------------
clk_pad/xcv2.u0/ol
Logic:
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/dll 20 118.8

3.6 5.3
clkgen0/xc2v.v/dll0 20 100.0 3.0 4.5
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/clkscale.dllm 20

100.0 3.0 4.5
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/bufg1.GCLKMUX 5

118.8 0.9 1.4
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/bufg2.GCLKMUX 5

118.8 0.9 1.4
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/bufg3.GCLKMUX 5

118.8 0.9 1.4
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/bufg4.GCLKMUX 5

118.8 0.9 1.4
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/clkscale.bufg0.GCLKMUX

5 118.8 0.9 1.4
clk_pad/xcv2.u0/g2.ttl0.bf.GCLKMUX 5 100.0 0.8

1.1
clkgen0/xc2v.v/bufg1.GCLKMUX 5 100.0 0.8 1.1
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/clkscale.bufg1.GCLKMUX

5 100.0 0.8 1.1
clkgen0/xc2v.v/bufg0.GCLKMUX 5 69.5 0.5 0.8
Nets:
clkm 0 769 69.5 80.3 120.4
clkml 0 94 118.8 16.8 25.2
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/clk_0r 0 51 118.8

9.3 13.9
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/clk_90r 0 43 118.8

7.8 11.7
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/clk_180r 0 40 118.8

7.2 10.7
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/mclk 0 12 118.8

2.2 3.4

----------------------------------------------------------------------
this is how my original file look exactly. so will it be possible to sum P(mW) column for all lines beginining with ddrsp0. Problem is that that all the values for a particular line beginning with ddrsp0 might not be on the same line like

ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/mclk 0 12 118.8

2.2 3.4

so what can I do for this because above mentioned scripts are not working properly in this case.

Thanks
# 7  
Old 04-26-2007
Code:
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/bufg4.GCLKMUX 5 

118.8 0.9 1.4
ddrsp0.ddr0/ddr_phy0/xc2v.ddr_phy0/mclk 0 12 118.8 

2.2 3.4

In some of the rows there are only 4 numeric data and in other rows you have 5 numeric data.Which field is P(mW)?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extracting data from one file, based on another file (splitting)

Dear All, I have two files but want to extract data from one based on another... can you please help me file 1 David Tom Ellen and file 2 David|0010|testnamez|resultsz David|0004|testnamex|resultsx Tom|0010|testnamez|resultsz Tom|0004|testnamex|resultsx Ellen|0010|testnamez|resultsz... (12 Replies)
Discussion started by: A-V
12 Replies

2. UNIX for Dummies Questions & Answers

Extracting line1 from a file with certain file pattern in line 7

Hello there, I am new to unix and would like to do the following, hoping someone would give some guide, thanks in advance. Lets say i have a file like this: A w x y w x 0.1 B w x y w x 0.3 C w x y w x 0.7 D w x y w x 0.9 E w x y w x 0.2 So i would like to extract line 1 data where line... (2 Replies)
Discussion started by: seiksoon
2 Replies

3. Shell Programming and Scripting

reading a file extracting information writing to a file

Hi I am trying to extract information out of a file but keep getting grep cant open errors the code is below: #bash #extract orders with blank address details # # obtain the current date # set today to the current date ccyymmdd format today=`date +%c%m%d | cut -c24-31` echo... (8 Replies)
Discussion started by: Bruble
8 Replies

4. Shell Programming and Scripting

extracting line numbers from a file and redirecting them to another file

i have applied the following command on a file named unix.txt that contains the string "linux from the text" grep -n -i -w "linux from the text" unix.txt and the result is 5:Today's Linux from the text systems are split into various branches, developed over time by AT&T as well as various... (5 Replies)
Discussion started by: arindamlive
5 Replies

5. Shell Programming and Scripting

Extracting a column from a file and merging with other file using awk

Hi All: I have following files: File 1: <header> text... text .. text .. text .. <\header> x y z ... File 2: <header> text... text .. text .. (4 Replies)
Discussion started by: mrn006
4 Replies

6. Shell Programming and Scripting

extracting columns using pattern file from source file

Hi experts,Please help me for the below requirement. i have a source file.(lets say contains 50 columns). I am extarcting five columns from the source file by using pattern file. for example input file:--------a,b,c,d,"a,g","v b",s,koutputfile=======a,"a,g","v b",s,kThanks in advance subhendu (2 Replies)
Discussion started by: subhendu81
2 Replies

7. Shell Programming and Scripting

Parsing file, yaml file? Extracting specific sections

Here is a data file, which I believe is in YAML. I am trying to retrieve just the 'addon_domains" section, which doesnt seem to be as easy as I had originally thought. Any help on this would be greatly appreciated!! I have been trying to do this in awk and mostly bash scripting instead of perl... (3 Replies)
Discussion started by: Rhije
3 Replies

8. Shell Programming and Scripting

Extracting data from text file based on configuration set in config file

Hi , a:) i have configuration file with pattren <Range start no>,<Range end no>,<type of records to be extracted from the data file>,<name of the file to store output> eg: myfile.confg 9899000000,9899999999,DATA,b.dat 9899000000,9899999999,SMS,a.dat b:) Stucture of my data file is... (3 Replies)
Discussion started by: suparnbector
3 Replies

9. Shell Programming and Scripting

[Splitting file] Extracting group of segments from one file to others

Hi there, I need to split one huge file into separate files if the condition is fulfilled according to that the position between 97 and 98 matches with “IT” at the segment MAS. There is no delimiter file is fix-width with varous line length. Could you please help me how I do split the file... (1 Reply)
Discussion started by: ozgurgul
1 Replies

10. Shell Programming and Scripting

Extracting IP's from a file

I've been trying to work out a way to extract IP's from a file. The IP's are contained withing brackets like this: is there a way to extract just the IP's or at least everything from the starting to ending bracket with grep or something similar? Thanks in advance. (14 Replies)
Discussion started by: eth0
14 Replies
Login or Register to Ask a Question