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
    #1  
Old Unix and Linux 06-23-2013
newbie_01 newbie_01 is offline
Registered User
 
Join Date: May 2009
Last Activity: 11 November 2016, 12:28 AM EST
Posts: 215
Thanks: 40
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 Unix and Linux 06-23-2013
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 7 December 2016, 5:21 AM EST
Location: San Jose, CA, USA
Posts: 9,729
Thanks: 459
Thanked 3,321 Times in 2,841 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 Unix and Linux 06-23-2013
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 7 December 2016, 7:02 AM EST
Location: Aachen, Germany
Posts: 9,923
Thanks: 200
Thanked 2,951 Times in 2,752 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
 

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 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 10:21 AM.