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
    #1  
Old 06-23-2013
newbie_01 newbie_01 is offline
Registered User
 
Join Date: May 2009
Last Activity: 24 July 2014, 3:06 PM EDT
Posts: 171
Thanks: 29
Thanked 0 Times in 0 Posts
Help with awk'ing formatting this

Hi,

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


Code:
$ nl /tmp/x

     1  ADRCI: Release 11.2.0.3.0 - 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
    #2  
Old 06-23-2013
Don Cragun's Avatar
Don Cragun Don Cragun is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 24 July 2014, 9:12 PM EDT
Location: San Jose, CA, USA
Posts: 4,135
Thanks: 162
Thanked 1,412 Times in 1,197 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
    #3  
Old 06-23-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 24 July 2014, 5:37 PM EDT
Location: Aachen, Germany
Posts: 3,878
Thanks: 62
Thanked 920 Times in 873 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:
Code:
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
SHORTP_POLICY:720

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 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 09:33 PM.