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!

Re: Complicated operation on output using AWK

Status
Not open for further replies.

annietech

Programmer
Aug 8, 2005
8
US
Hi,

I have a problem with my script which processes my oracle output. Here is part of the sample output:

Unix File System TBS Name 10% Size
/data/oracle/R1LD/data03/ TSINDEX 204800
/data/oracle/R1LD/data03/ TSINDEX 204800
/data/oracle/R1LD/data04/ TSINDEX 204800
/data/oracle/R1LD/data04/ TSINDEX 204800
/data/oracle/R1LD/data04/ TSINDEX 204800
/data/oracle/R1LD/data05/ TSINDEX 204800
/data/oracle/R1LD/data05/ TSINDEX 204800
/data/oracle/R1LD/data05/ TSINDEX 204800

Each Record is seperated by newline and each field is seperated by tab. The task definition is:

Loop through all the rows, and for each distinct "File System" ($1), sum up the "10% Size" ($3), if the sum is smaller than a given value, store "TBS NAME" ($2) for those records.

At the end of AWK, print out all the "TBS NAME"s stored in the loop and direct output to a file.

I'm struggling with manipulating records using AWK to do complicated operations like this. I was adviced to use another language to write this programme but time is very limited.

Thank you in advance for your help! :)
 
Hi

I think you need something like this :
Code:
{
  size[$1]+=$3
  name[$1]=$2
}
END {
  for (x in size) if (size[x]<1000000) print name[x] > "outputfile.txt"
  close("outputfile.txt")
}

Feherke.
 
Hi Feherke,

Thanks a lot for your help. Your code follows the right logic but the outputfile.txt have many lines missing. It seems like awk just chunk out some random lines instead of really comparing if $3 is < 1000000 . The correct result should return all the records with the $2 only.

Do you have any idea why is it doing this?

Cheers,
Annie
 
Hi Feherke,

You're 100% right! I am looking for a grouped result so I expect the size array gives me 3 numbers, indicating sum of rows that have the same values in $1. (Please see below output, seperated by a blank line)

Unix File System TBS Name 10% Size
/data/oracle/R1LD/data03/ TSINDEX 204800
/data/oracle/R1LD/data03/ ABCDEFC 204800

/data/oracle/R1LD/data04/ WEJRWEJ 204800
/data/oracle/R1LD/data04/ WJEEWIE 204800
/data/oracle/R1LD/data04/ JFIOWWE 204800

/data/oracle/R1LD/data05/ JOWIERW 204800
/data/oracle/R1LD/data05/ JKJIOWE 204800
/data/oracle/R1LD/data05/ PWERKEW 204800

Therefore the sum of each group will be 409600, 614400, 614400. So say the if statment was, " < 500000 ", then the awk program will return TSINDEX, ABCDEFC correspondingly.

Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top