Monday, April 16, 2012

Awk to analyse text file

Example 1

Pivot text contents

gawk -F= '/ORACLE_HOME/{gsub(" |\t|)","",$2);h=$2}/SID_NAME/{gsub(" |\t|)","",$2);s=$2; printf("%-20s%-50s\n",s,h)}' listener.ora

Example 2

BEGIN {
  FS = "\n"
}
{
      format = "%Y/%m/%d"
      while (( getline variableLine ) > 0)
      {
#       split (variableLine, variableLineArray," ")
        split (variableLine, variableArray, " ")
        if (variableArray[4] == "999999999")
        {
          print variableArray[1] , variableArray[2] " , ----"
        }
        else
        {
          print variableArray[1] , variableArray[2] " ," strftime(format,variableArray[4])
        }
      }
}
Time function:

http://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html#Time-Functions

No comments:

Post a Comment