complex Awk Question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting complex Awk Question
# 1  
Old 08-07-2011
complex Awk Question

Hi,
I have a file look likes this :

--->start hir
Code:
Trace file: pudwh_ora_9998.trc
Sort options: fchela  exeela  
***************************************************************count    = number of times OCI procedure was executed
cpu      = cpu time in seconds executing 
elapsed  = elapsed time in seconds executing
disk     = number of physical reads of buffers from disk
query    = number of buffers gotten for consistent read
current  = number of buffers gotten in current mode (usually for update)
rows     = number of rows processed by the fetch or execute call
***************************************************************
CREATE TABLE UAC_37662_ga NOLOGGING  AS SELECT DISTINCT 
  CRM.CI_CUST_INFO.NAP_INT_CUST_NUM FROM CRM.CI_CUST_INFO WHERE 
  CRM.CI_CUST_INFO.LAST_MIV_STATUS_PAC_DECSR IN ( 'פעיל' )


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        0      0.00       0.00          0          0          0           0
Execute      1     18.31     239.91        326    4999384        631      368776
Fetch        0      0.00       0.00          0          0          0           0
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total        1     18.31     239.91        326    4999384        631      368776

Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer mode: ALL_ROWS
Parsing user id: 94  
***************************************************************
SELECT NAP_INT_CUST_NUM 
FROM
 UAC_37662_ga ORDER BY NAP_INT_CUST_NUM 


call     count       cpu    elapsed       disk      query    current        rows
------- ------  -------- ---------- ---------- ---------- ----------  ----------
Parse        1      0.00       0.00          0          0          0           0
Execute      1      0.00       0.00          0          0          0           0
Fetch       74      0.51       0.59          0        155          0      368776
------- ------  -------- ---------- ---------- ---------- ----------  ----------
total       76      0.51       0.59          0        155          0      368776

Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 94  
....

---> End hir

I would like to print only the following output :

Code:
    elapsed 
 ---------- 
       0.00 
     239.91 
       0.00 
 ---------- 
     239.91 


    elapsed 
 ---------- 
       0.00 
       0.00 
       0.59 
 ---------- 
       0.59

I tryied :

Code:
cat filename.txt | awk '{print $4} '

But its not enough since i get all the output under column 4.

Thanks

Last edited by pludi; 08-07-2011 at 03:47 PM..
# 2  
Old 08-07-2011
First thing to point out, you don't need to cat your file to awk. Awk can read your file directly.

Second thing, you just need to add a few bits that tell the awk when to start printing the desired column and when to stop:

Code:
awk '
    /total / { 
        printf( "%s\n\n",  $4);     # print total and stop snarfing
        snarf = 0; 
        next; 
    }

    snarf > 0 {             # ok to snarf, so print the field
        print $4; 
        next; 
    }

    /call count cpu elapsed / {         # trigger the start of printing
        print $4; 
        snarf = 1; 
        next; 
    }
' input_file

Hope this helps.
# 3  
Old 08-07-2011
Using ranges:
Code:
mute@atom:~$ awk '/^call/,/^$/ { print $4 }' file
elapsed
----------
0.00
239.91
0.00
----------
239.91

elapsed
----------
0.00
0.00
0.59
----------
0.59

or keep right-aligned with
Code:
 printf("%10s\n", $4)

# 4  
Old 08-07-2011
Code:
awk '$1=="call"{f++}f{print $4}$1=="total"{f--}' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk in complex number data

Hi, I'm trying to transform my data from the following format: eps:, 0.248281687841641, -2.83539034165844e-7, 2.78042576353472+6.3505226053266e-6i to this: eps:, 0.248281687841641, -2.83539034165844e-7, 2.78042576353472, +6.3505226053266e-6 so I can plot it with GnuPlot. how do I... (4 Replies)
Discussion started by: rogeriogouvea
4 Replies

2. Shell Programming and Scripting

Building a complex xml using awk

Hi I have a complex xml to be build using awk using a lookup file values. Below is the xml <country name="xyz"> <state name="abc"> <city name="qwe" capital="yes"/> <city name="asd" capital="no"/> </state> <state name="qrq"> <city name="rthy" capital="yes"/> <state> </country> ... (1 Reply)
Discussion started by: Nevergivup
1 Replies

3. Shell Programming and Scripting

Complex awk problem

hello, i have a complex awk problem... i have two tables, one with a value (0 to 1) and it's corresponding p-value, like this: 1. table: ______________________________ value p-value ... ... 0.254 0.003 0.245 0.005 0.233 0.006 ... ... ______________________________ and a... (6 Replies)
Discussion started by: dietmar13
6 Replies

4. Shell Programming and Scripting

Complex transpose awk script

Hello to all in forum, Maybe an awk expert could help me with this complex task for me. I have the input shown below and I would like to get the output as follow: - I would like the output separated by commas. - The header is fixed and will be the same always. - For the lines containing... (22 Replies)
Discussion started by: Ophiuchus
22 Replies

5. Shell Programming and Scripting

Help with Complex Awk.

Hi, I have a file. In this file when ever the word "ABC" occurs at position from 25 and 34 I would like to replace the value at postion 100 to 5 for the first 1000 rows only. I have written the following Awk command. nawk 'substr($0,25,9)=="ABC" {print $0}' filename The above command... (4 Replies)
Discussion started by: pinnacle
4 Replies

6. Shell Programming and Scripting

awk script (complex)

picked this up from another thread. echo 1st_file.csv; nawk -F, 'NR==FNR{a++;next} a{b++} END{for(i in b){if(b-1&&a!=b){print i";\t\t"b}else{print "NEW:"i";\t\t"b} } }' OFS=, 1st_file.csv *.csv | sort -r i need to use the above but with a slight modification.. 1.compare against 3 month... (25 Replies)
Discussion started by: slashbash
25 Replies

7. Shell Programming and Scripting

Sorting complex file with awk

i have a file ddd.txt its delimiter is : but has , and "" within each column as below and also each line ends with ; I_EP,"29":I_US,"120":I_P_ID,"2020":I_NEW,"600":I_OLD,"400":I_POW,"4.5":I_NAME,"TOM";... (9 Replies)
Discussion started by: blackzinga80
9 Replies

8. Shell Programming and Scripting

perl : semi complex if statement question

Hi there I am trying to write an if statement in perl that will return "SUCCESS" if either of these conditions are true a) if $changes is greater than 5 AND the $force flag is set to 1 OR b) if $changes is greater than 0 AND $changes is less than 6 #!/usr/bin/perl -w my $force =... (5 Replies)
Discussion started by: rethink
5 Replies

9. Shell Programming and Scripting

Complex use with awk

Hi , I have file named docs.txt The content of the file look like this: DOC disk location Size ======= ===== ============= ========= TXT A /dev/dm-1 10 TXT B /dev/dm-2 10 BIN C ... (3 Replies)
Discussion started by: yoavbe
3 Replies

10. Shell Programming and Scripting

Complex Sed/Awk Question?

Hello, So i have this file called /apps/turnout which looks like that of the contents of the /etc/shadow (but not exactly) the file has a long list in it. basically, the contents of this file looks something similar to the following: jajajajalala:D#$#AFVAdfda lalabavisof:#%R@fafla#$... (3 Replies)
Discussion started by: SkySmart
3 Replies
Login or Register to Ask a Question