Help with awk'ing formatting this | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    

UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Help with awk'ing formatting this

UNIX for Dummies Questions & Answers

Closed Thread    
Thread Tools Search this Thread Display Modes
Old 06-23-2013
newbie_01 newbie_01 is offline
Registered User
Join Date: May 2009
Last Activity: 26 February 2015, 1:35 AM EST
Posts: 177
Thanks: 29
Thanked 0 Times in 0 Posts
Help with awk'ing formatting this


I have a file below that I am wanting to awk. The lines of relevance are lines 7 and 9

$ nl /tmp/x

     1  ADRCI: Release - Production on Sun Jun 23 17:01:02 2013

     2  Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.

     3  ADR base = "/u01/app/grid"
     4  adrci> adrci>
     5  ADR Home = /u01/app/grid/diag/asm/user_grid/host_3970975860_80:
     6  *************************************************************************
     7  ADRID                SHORTP_POLICY        LONGP_POLICY         LAST_MOD_TIME                            LAST_AUTOPRG_TIME                        LAST_MANUPRG_TIME                        ADRDIR_VERSION       ADRSCHM_VERSION      ADRSCHMV_SUMMARY     ADRALERT_VERSION     CREATE_TIME             
     8  -------------------- -------------------- -------------------- ---------------------------------------- ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- -------------------- ----------------------------------------
     9  1459756123           720                  8760                 2011-05-16 18:00:59.590482 +12:00                                                                                          1                    2                    80                   1                    2011-05-16 18:00:59.590482 +12:00
    10  1 rows fetched

    11  adrci>

At the moment what I am doing is re-directing both lines to a file each using sed. Is there any way that I can awk it right away once I re-direct the output to a file?

The line that is important is line 7, I was hoping I can reference each field based on each heading. For example, if want to be able access SHORTP_POLICY and shows 720 :-)

I do not have much control on how the output looks like and I hope it stays this way even on future Oracle upgrades ... grrr ....

FYI, shell that I am using is ksh.

Any feedback much appreciated. Thanks in advance.
Sponsored Links
Old 06-23-2013
Don Cragun's Avatar
Don Cragun Don Cragun is online now Forum Staff  
Join Date: Jul 2012
Last Activity: 2 March 2015, 1:55 AM EST
Location: San Jose, CA, USA
Posts: 5,752
Thanks: 234
Thanked 1,908 Times in 1,626 Posts
With well over a hundred posts in the UNIX & Linux Forums, you should know that to be able to help we need a lot more details:
  1. What are you using to create /tmp/x?
  2. What sed commands are you using to redirect output to other files?
  3. Do lines 7 and 9 in /tmp/x contain tabs or just spaces?
  4. How exactly do you want to refer to a field and what results do you want when you refer to that field?
  5. And, most importantly, what have you tried?
Sponsored Links
Old 06-23-2013
RudiC RudiC is offline Forum Advisor  
Registered User
Join Date: Jul 2012
Last Activity: 1 March 2015, 12:06 PM EST
Location: Aachen, Germany
Posts: 5,413
Thanks: 94
Thanked 1,410 Times in 1,328 Posts
With some searching in these fora you could have dreamed up a solution yourself, as quite similar problems have been posted here before. Anyhow - try this and adapt to your needs:
awk     'FNR==9         {for (n=1; n<=NF; n++) if ($n==SRCH) {COL=n; break};  next}
         FNR==11        {print SRCH ":" $COL}
        ' SRCH="SHORTP_POLICY"  file

The lines you are looking for are lines 9 and 11, resp., as nl does not count empty lines if not asked to do so.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
formatting awk rocking77 Shell Programming and Scripting 5 06-17-2011 01:23 PM
AWK formatting help. Peasant Shell Programming and Scripting 5 04-22-2011 12:43 PM
pipe'ing grep output to awk ziggy25 Shell Programming and Scripting 2 12-14-2009 03:25 AM
grep'ing and sed'ing chunks in bash... need help on speeding up a log parser. elinenbe Shell Programming and Scripting 4 04-21-2009 02:40 PM
Formatting using awk cdunavent Shell Programming and Scripting 2 03-18-2003 02:09 PM

All times are GMT -4. The time now is 03:20 AM.