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 -->
  #2 (permalink)  
Old 11-20-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131
nawk -f deep.awk abc.txt

deep.awk:

Code:
BEGIN {
  FS=RS=""

  prefix=substr(FILENAME, 1, index(FILENAME, ".")-1)
}
{
   root="unknown"
   for(i=1; i<=NF; i++)
      if ($i ~ "Company Code") {
         n=split($2, a, " ")
         root=a[n]
         break
      }
   out= prefix "_COMCODE_" root ".txt"
   print > out
   close(out)
}