The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-17-2008
timj123 timj123 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 80
Help with awk funcions

I have a issue with my script. It works for the most part but is not very
portable. Example below is sample of "input file" and cut and paste of "script.

The script works fine if The following System portions are outputted as follows:

SYSTEM CFO is followed by SYSTEM DAX
SYSTEM DAX is followed by SYSTEM TC
SYSTEM TC is followed by STETEM OND

On different Units some of the System portions are not outputted in the same
order or some of the System portions are not outputted at all.

My question is how can I modify awk functions to stop processing on one system
and start processing on the next system portion when the next system portion
is not listed in the portion itself, example of function(dAX):
Code:
   while (( getline > 0 ) && ( $3 != "TC" )) {
In the above line of code, $3 TC is the next system portion, that tells function to stop processing.

Here is sample of input file:

Code:
doal   cont   pegc   system1   call7   solh
RX SYSTEM CFO
DATE 322:47:34

DPORQ = 0        TTORQ = 0        DPINRQ= 0
MFINRQ= 0        CDIRR = 0        TCBSY = 0
TCINT = 0        TCANS = 0        TCRNG = 0
RPINRQ= 0        C6INRQ= 0        ISUPRQ= 11147
TUPRQ = 0        MFOURQ= 0        C6OURQ= 0
ISUPOR= 17417    BICCRQ= 0        BICCOR= 0
POVFL = 0

doal   cont   pegc   system1   call7   solh
RX SYSTEM DAX
DATE 322:47:34

proc   cpu    systm    load     sactv    orig    ovldpu   mmst
1      0        0        0        0        0        0        0
2      0        0        0        0        0        0        0
3      0        0        0        0        0        0        0
4      0        0        0        0        0        0        0
5      0        0        0        0        0        0        0
6      0        0        0        0        0        0        0
7      0        0        0        0        0        0        0
8      0        0        0        0        0        0        0
9      0        0        0        0        0        0        0
10     0        0        0        0        0        0        0
11     0        0        0        0        0        0        0

doal   cont   pegc   system1   call7   solh
RX SYSTEM TC
DATE 322:47:34

proc     pucco    load     chgro    chmert   chinc    chout    ceqpu
22       2        97       0        0        2707     6374     0
1        3        15011    0        0        2717     6651     0
2        3        12976    0        0        2139     6137     0
3        3        13898    0        0        2199     6583     0
4        3        15123    0        0        2478     7788     0
5        3        13823    0        0        2645     5789     0
Here is sample of script:
Code:
/usr/xpg4/bin/awk '

$3 == "CFO"    { cFO() } 
$3 == "DAX"    { dAX() } 
$3 == "TC"     { tC()  } 


function dAX(     _xm)
{
   while (( getline > 0 ) && ( $3 != "TC" )) {

do a a lot of awk stuff here....
.
.
.
.
.
   }
}

function tC(     _msx)
{
   while (( getline > 0 ) && ( $3 != "OND" )) {

do a a lot of awk stuff here....
.
.
.
.
.
   }
}

function cFO(     _iu)
{
   while (( getline > 0 ) && ( $3 != "DAX" )) {

do a a lot of awk stuff here....
.
.
.
.
.
   }
} FILENAME
Thanks in advance.
  #2 (permalink)  
Old 11-18-2008
timj123 timj123 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 80
Is there a way to maybe read in entire file first to determine next system section? I was wanting to avoid doing this because the files are really big.
  #3 (permalink)  
Old 11-19-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Why don't you just change the condition where it stops, i.e. when you hit the "doal" line?

Code:
    while (getline && $1 != "doal") {
If you need to do any processing of the "doal" line contents you can just do it after the while loop.
  #4 (permalink)  
Old 11-19-2008
timj123 timj123 is offline
Registered User
  
 

Join Date: Jan 2008
Posts: 80
Annihilannic,
First Thanks for looking at this for me.

But unfortunately the data I posted was only a snippet of what I have. Sometimes the data is as follows:

Code:
doal   cont   pegc   system1   call7   solh
RX SYSTEM CFO
DATE 322:47:34

DPORQ = 0        TTORQ = 0        DPINRQ= 0
MFINRQ= 0        CDIRR = 0        TCBSY = 0
TCINT = 0        TCANS = 0        TCRNG = 0
RPINRQ= 0        C6INRQ= 0        ISUPRQ= 11147
TUPRQ = 0        MFOURQ= 0        C6OURQ= 0
ISUPOR= 17417    BICCRQ= 0        BICCOR= 0
POVFL = 0

doal   cont   pegc   system1   call7   solh
RX SYSTEM CFO
DATE 322:47:34

DPORQ = 0        TTORQ = 0        DPINRQ= 0
MFINRQ= 0        CDIRR = 0        TCBSY = 0
TCINT = 0        TCANS = 0        TCRNG = 0
RPINRQ= 0        C6INRQ= 0        ISUPRQ= 11158
TUPRQ = 0        MFOURQ= 0        C6OURQ= 0
ISUPOR= 17459    BICCRQ= 0        BICCOR= 0
POVFL = 0

doal   cont   pegc   system1   call7   solh
RX SYSTEM DAX
DATE 322:47:34

proc   cpu    systm    load     sactv    orig    ovldpu   mmst
1      0        0        0        0        0        0        0
2      0        0        0        0        0        0        0
3      0        0        0        0        0        0        0
4      0        0        0        0        0        0        0
5      0        0        0        0        0        0        0
6      0        0        0        0        0        0        0
7      0        0        0        0        0        0        0
8      0        0        0        0        0        0        0
9      0        0        0        0        0        0        0
10     0        0        0        0        0        0        0
11     0        0        0        0        0        0        0
And I need to process both sections as one. But you did give me a idea on how else to solve if possible. Is there a way to test the line below without doing any processing on that line??? I'll try to explain on this untested code:

Code:
while (( getline > 0 ) && ( $1 != "doal" ) && ( getline ; $3=! "CFO"))
What I am trying to say is, is it possible to test $3 below the "doal" line?
  #5 (permalink)  
Old 11-19-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
It's difficult to advise you without knowing what the code is doing inside those while loops, but in your position I would try and avoid using them completely, and do something more like this:

Code:
awk '
        /^RX SYSTEM/ { section=$3 }
        section=="CFO" {
                print "processing CFO stuff: " $0
        }
        section=="DAX" {
                print "processing DAX stuff: " $0
        }
        section=="TC" {
                print "processing TC stuff: " $0
        }
' inputfile > outputfile
It is possible to "look ahead" at subsequent lines by storing each line as you read it in a variable, and processing the data stored in the variable when you read the subsequent line, with the slight complication that you need to handle the last line of data in the END {} clause of your script.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:37 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0