![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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" )) {
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 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
|
|
||||
|
Why don't you just change the condition where it stops, i.e. when you hit the "doal" line?
Code:
while (getline && $1 != "doal") {
|
|
||||
|
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 Code:
while (( getline > 0 ) && ( $1 != "doal" ) && ( getline ; $3=! "CFO")) |
|
||||
|
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
|
| Sponsored Links | ||
|
|