Unix/Linux Go Back    

UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Help with awk'ing formatting this

UNIX for Dummies Questions & Answers

Thread Tools Search this Thread Display Modes
Old Unix and Linux 06-23-2013
newbie_01 newbie_01 is offline
Registered User
Join Date: May 2009
Last Activity: 18 October 2017, 2:14 AM EDT
Posts: 228
Thanks: 44
Thanked 1 Time in 1 Post
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 Unix and Linux 06-23-2013
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Join Date: Jul 2012
Last Activity: 20 October 2017, 3:27 AM EDT
Location: San Jose, CA, USA
Posts: 10,544
Thanks: 551
Thanked 3,693 Times in 3,151 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 Unix and Linux 06-23-2013
RudiC RudiC is offline Forum Staff  
Join Date: Jul 2012
Last Activity: 19 October 2017, 11:23 AM EDT
Location: Aachen, Germany
Posts: 11,477
Thanks: 310
Thanked 3,560 Times in 3,276 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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 12:23 PM
AWK formatting help. Peasant Shell Programming and Scripting 5 04-22-2011 11:43 AM
pipe'ing grep output to awk ziggy25 Shell Programming and Scripting 2 12-14-2009 02: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 01:40 PM
Formatting using awk cdunavent Shell Programming and Scripting 2 03-18-2003 01:09 PM

All times are GMT -4. The time now is 04:52 AM.