The UNIX and Linux Forums  

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




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #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.