Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help in AWK statement Extract and condition 1

Status
Not open for further replies.
Sep 22, 2004
27
US
i have in directories /prod/test/data*(01-24)/testr

-rw-rw-rw- 1 1976 Nov 25 00:41 20030117estats.001
-rw-r--r-- 1 32768 Nov 26 11:43 b2030411nlod.001
-rw-r--r-- 1 8192 Nov 26 11:43 a2030411nlod.001
-rw-r--r-- 1 8192 Nov 26 11:43 b1030411nlod.001
-rw-r--r-- 1 8192 Nov 26 11:43 a4030411nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 m1030211nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 m2031011nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 m4031012nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 n1031012nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 n4031012nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 o3031012nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 o4031012nlod.001

i have to extract the bytes in column 3 for corresponding (nlod .001) files only in column 6 and for a particular date (m4031012nlod.001 = m4YYMMDDnlod.001 ;corresponds to
date of 20031012). The nlod files are dumped dynamically into directories data* - ranging from (01 -24 "?") and hence the files for a particular date can be located in anyone of these directories depending upon the space availability at run time.
Im trying to get a COUNT of the nlod files for a particular date ,with the bytes displayed and also the counts of nlods files having *bytes which signifies an error.
Im trying to write an awk statement to extract fileds but im not being successful in adding conditions within awk.
Please advice on going through this.
Thanks in advance!
 
just some rough thoughts:

create a file that has the file list with directories included.

get the count of that file

create another file with only date info

sort unique on the date file

use a simple loop such as for ; ; to check each line in that file against the unique date. If the date column equals to a certain date, increment that date count.

Hope it helps
 
joeroe3380, see if this works.
Code:
# Trim trailing whitespace.
{ sub( /[ \t]+$/, "" ) }

/nlod\.001$/ {
  date = substr( $NF, 3, 6 )
  counts[date]++
  if ("*"==$3)
    errors[date]++
  else
    bytes[date] += $3
}

END {
  fmt = "%-7s%6s%10s%8s\n"
  printf fmt, "Date", "Count", "Bytes", "Errors"
  for (k in counts)
  { printf fmt, k, counts[k], bytes[k]+0, errors[k]+0
  }
}
With this input
[tt]
-rw-rw-rw- 1 1976 Nov 25 00:41 20030117estats.001
-rw-r--r-- 1 32768 Nov 26 11:43 b2030411nlod.001
-rw-r--r-- 1 8192 Nov 26 11:43 a2030411nlod.001
-rw-r--r-- 1 8192 Nov 26 11:43 b1030411nlod.001
-rw-r--r-- 1 8192 Nov 26 11:43 a4030411nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 m1030211nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 m2031011nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 m4031012nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 n1031012nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 n4031012nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 o3031012nlod.001
-rw-r--r-- 1 8 Nov 28 00:41 o4031012nlod.001
-rw-r--r-- 1 * Nov 28 00:41 m1030211nlod.001
[/tt]
the output is
[tt]
Date Count Bytes Errors
030211 2 8 1
031011 1 8 0
031012 5 40 0
030411 4 57344 0
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top