Feeding information in columns of LOG file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Feeding information in columns of LOG file
# 8  
Old 11-20-2011
Hi,
Many thanks & sorry for bothering again and again..
Actually, the script is working perfect when I am saying "lines= 8". But when I mentioned lines=20 for the following piece of code.

Code:
 =======using photon counter ======
tot pho is                 = 8453
nomatch pho is             = 413
phoeta pho is              = 375
nospike_counter is         = 375
et cut passed pho          = 200
ecal cut passed pho        = 204
hcal cut passed pho        = 185
trk cut passed pho         = 81
sieie cut passed pho       = 109
hoe cut passed pho         = 186
pixsed cut passed pho      = 285
et_ecal                    = 103
et_ecal_hcal               = 53
et_ecal_hcal_trk           = 26
et_ecal_hcal_trk_Sie       = 19
et_ecal_hcal_trk_Sie_hoe   = 18
pho ID passed              = 16
no Rho correction          = 16
loose SIEIE :              = 18
no rho &&  loose phoID     = 18
============================


here is the output.
Code:
tot pho is                 = 8453 29596 24989 30046 3382 2351 2507 1833 615 13805 20761 11024 22473 21973 14903 12471 16496 6841 4430 4420 5838 13812 273019
nomatch pho is             = 413 1350 1169 1374 167 149 121 89 26 635 1025 492 1034 991 717 680 763 317 195 215 256 690 12868
phoeta pho is              = 375 1220 1042 1242 153 128 109 77 22 569 923 444 938 879 635 605 684 290 177 185 224 620 11541
nospike_counter is         = 375 1220 1042 1242 153 128 109 77 22 569 923 444 938 879 635 605 684 290 177 185 224 620 11541
et cut passed pho          = 200 674 576 694 88 70 58 36 11 297 520 213 511 478 356 303 380 147 98 90 138 334 6272
ecal cut passed pho        = 204 614 542 644 70 66 47 49 12 290 481 224 509 448 336 326 384 154 100 91 115 333 6039
hcal cut passed pho        = 185 570 457 574 74 66 49 38 10 265 419 222 426 403 292 267 310 141 78 91 100 317 5354
trk cut passed pho         = 81 240 190 223 26 30 16 16 7 104 192 102 201 172 142 124 134 54 34 31 48 120 2287
sieie cut passed pho       = 109 377 341 365 38 33 26 21 3 171 279 138 283 255 217 180 210 100 69 55 63 194 3527
hoe cut passed pho         = 186 580 471 582 67 63 52 38 11 244 420 225 413 404 306 299 335 159 85 89 99 305 5433
pixsed cut passed pho      = 285 888 778 955 115 92 87 60 16 434 692 338 713 656 484 451 515 226 129 139 172 442 8667
et_ecal                    = 103 321 287 338 37 32 21 17 6 143 248 91 265 230 189 148 211 75 49 47 65 180 3103
et_ecal_hcal               = 53 173 159 165 22 20 16 9 3 68 136 56 136 126 105 64 103 33 20 28 37 102 1634
et_ecal_hcal_trk           = 26 77 68 66 11 13 1 4 3 29 60 23 62 55 52 32 47 13 9 13 18 33 715
et_ecal_hcal_trk_Sie       = 19 59 50 49 7 10 1 3 2 21 44 15 45 40 45 23 33 12 9 8 15 23 533
et_ecal_hcal_trk_Sie_hoe   = 18 53 45 41 7 9 1 3 1 20 40 13 43 35 41 19 31 12 8 6 15 23 484
pho ID passed              = 16 38 39 35 5 8 1 3 1 18 33 13 31 28 31 17 26 11 5 3 14 17 393
no Rho correction          = 16 18 38 44 39 43 35 40 5 6 8 9 1 1 3 3 1 1 18 20 33 34 13 15 32 36 28 32 31 33 17 18 26 29 11 11 5 5 3 4 14 14 17 19 829
loose SIEIE :              = 18 44 43 40 6 9 1 3 1 20 34 15 36 32 33 18 29 11 5 4 14 19 435
no Rho correction          = 16 18 38 44 39 43 35 40 5 6 8 9 1 1 3 3 1 1 18 20 33 34 13 15 32 36 28 32 31 33 17 18 26 29 11 11 5 5 3 4 14 14 17 19 829

As is clear that the last variable
Code:
 no rho &&  loose phoID

is not being read.
The variable
Code:
 no Rho correction

is being read twice besides have double entries (has 44 entries whereas rest have 22 entries ).

hope, the reason must be something obvious..

Thanks again
pooja..
# 9  
Old 11-20-2011
The code uses the first value as the array index which I assumed will be unique... but doesn't seem to be...

Try this...
Code:
awk '/using photon counter/{p=lines;next}
p>0{
        split($0,arr,"=")
        if(!h[arr[1]"HDR"])h[arr[1]"HDR"]=arr[1]
        a[arr[1]]=a[arr[1]]" "$NF
        if(j<lines) b[++j]=arr[1]
        sum[arr[1]]+=$NF
        p--
}
END{
        for(i=1;i<=j;i++)
                print h[b[i]"HDR"]"="a[b[i]]" "sum[b[i]]
}' lines=20 *.log > LOG

--ahamed
# 10  
Old 11-20-2011
hi ahamed,
Its Perfect..SmilieSmilie

thanks a lot..

Please explain in brief as what does the code meant.
pooja.
# 11  
Old 11-20-2011
Code:
awk '/using photon counter/{p=lines;next}
p>0{
        #take a sample line "tot pho is = 8453"
        split($0,arr,"=")       #split the line using "=" as the delimiter. arr[1] will have "tot pho is"
        if(!h[arr[1]"HDR"])h[arr[1]"HDR"]=arr[1]   #h is an array for storing the header values i.e. "tot pho is" for printing it later at the end
                                                        #It is stored in an associative array with "tot pho is" and "HDR" as the index
                                                        #It will look like this... h["tot pho is""HDR"]="tot pho is"    
        a[arr[1]]=a[arr[1]]" "$NF                       #a is another associtive array to store all the values after =
                                                        #It will look like this... a["tot pho is"]=8453 123 245
                                                        #a["nomatch pho is"]=556 854 653
        if(j<lines) b[++j]=arr[1]                       #b is used for maintaining the order as you requested
                                                        #b[1]="tot pho is"
                                                        #b[2]="nomatch pho is" etc
        sum[arr[1]]+=$NF                                #sum will calculate all the values 
                                                        #sum["tot pho is"]=8543+123+245 etc
        p--
}
END{
        #Finally printing!
        for(i=1;i<=j;i++)
                print h[b[i]"HDR"]"="a[b[i]]" "sum[b[i]]        
}' lines=20 *.log

HTH
--ahamed

PS : I may not be a good teacher... Smilie
# 12  
Old 11-20-2011
you really good at it..Smilie

Thnaks a lot
pooja..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Getting information out of a log file

Hello guys, I am trying to filter some information out of a log file (example shortcut) ===== fspCIV0 /vol/vol0 -sec=sys,rw=fspsanp42.net,root=fspsanp42.net,nosuid ===== fcvCIS01 /vol/ARDW -sec=sys,rw /vol/ARDW -sec=sys,rw /vol/ARDW -sec=sys,rw,nosuid /vol/ARDW -sec=sys,rw... (2 Replies)
Discussion started by: linux_scrub
2 Replies

2. Shell Programming and Scripting

Include information in certain columns using grep and awk

HI all, I have data in a file that looks like this: 1 HOW _ NNP NNP _ 3 nn _ _ 2 DRUGS _ NNP NNP _ 3 nn _ _ 3 ACT _ NNP NNP _ 0 null _ _ 4 : _ ... (3 Replies)
Discussion started by: owwow14
3 Replies

3. Shell Programming and Scripting

Remove lines with unique information in indicated columns

Hi, I have the 3-column, tab-separated following data: dot is-big 2 dot is-round 3 dot is-gray 4 cat is-big 3 hot in-summer 5 I want to remove all of those lines in which the values of Columns 1 and 2 are identical. In this way, the results would be as follows: dot is-big 2 cat... (4 Replies)
Discussion started by: owwow14
4 Replies

4. Shell Programming and Scripting

Parsing text file and feeding it into an executable

Hello, everyone. I am working wtihin AIX 5.3, and I need to do the following: read the each line of file BASE.txt do XK {line contents} if XK's output begins with "BASE", then append line contents to file "output.txt" continue until end of file Here is what I tried(unsuccessfuly): ... (4 Replies)
Discussion started by: Mordaris
4 Replies

5. Shell Programming and Scripting

Grep'ing information from a log file on SUN OS 5

Hi Guys, I'm trying to write an script that will be launched by a user. The script will look at a log file and check for alerts with the date (supplied by user) and a machine's hostname (also supplied by the user). I'm trying to get the output formatted just like the log file. The logfile looks... (5 Replies)
Discussion started by: illgetit
5 Replies

6. Shell Programming and Scripting

Extract various information from a log file

Hye ShamRock If you can help me with this difficult task for me then it will save my day Logs : ================================================================================================================== ... (4 Replies)
Discussion started by: SilvesterJ
4 Replies

7. Shell Programming and Scripting

extract information from a log file (last days)

I'm still new to bash script , I have a log file and I want to extract the items within the last 5 days . and also within the last 10 hours the log file is like this : it has 14000 items started from march 2002 to january 2003 awk '{print $4}' < *.log |uniq -c|sort -g|tail -10 but... (14 Replies)
Discussion started by: matarsak
14 Replies

8. Shell Programming and Scripting

Extract information from Log file formatted

Good evening! Trying to make a shell script to parse log file and show only required information. log file has 44 fields and alot of lines, each columns separated by ":". log file is like: first_1:3:4:5:6:1:3:4:5:something:notinterested second_2:3:4:3:4:2 first_1:3:4:6:6:7:8 I am interested... (3 Replies)
Discussion started by: dummie55
3 Replies

9. UNIX for Dummies Questions & Answers

Routing a verbose information to a log file

Hi All, In the script mentioned below uses a sftp command to login to the remote host and pull the files from the remote server. we want to log this inf to a log file . But it is not happening, the verbose information is just displayed on the screen but not to the log file when I run this... (1 Reply)
Discussion started by: raghuveer2008
1 Replies

10. Shell Programming and Scripting

Perl: adding columns in CSV file with information in each

Hi Wise UNIX Crew, I want to add 3 different columns to the file in which: 1. The first new column pulls in today's date and time 2. Second column one has a '0' 3. Third column has the word 'ANY' going down the column If my file content is as follows: "7","a","abc",123"... (1 Reply)
Discussion started by: dolo21taf
1 Replies
Login or Register to Ask a Question