Using csh / awk / sed to compare database sizes in a txt file

Hello,

I have an output file showing database sizes across the 3 environments that I use (LIVE, TEST & DEVELOPMENT).

I am trying to write a script that lets me know if the size of a db on one environment is different to its corresponding db on the other environments.

Here is an example of the file......(Name Size Environment)

stevie_db 13000   LIVE
stevie_db 13000   TEST
stevie_db 14000   DEVELOPMENT
john_db   25000   LIVE
john_db   25000   TEST
john_db   25000   DEVELOPMENT

I want to compare database sizes & flag up any databases that are a different size in any of the environments. So in the above example, the database stevie_db will be flagged up (because it is a different size in DEVELOPMENT). Maybe we could append an asterisk to any line that matches our criteria, to show it is different.

I imagine the general syntax would be something along the lines of
If $1 on line 1 = $1 on any other line

Compare $2 on lines 1 and the matching line, flag up an error if they are different sizes.

Move on to Line 2 (and so on).

Is this something that could be done in awk?

Any help would be really appreciated.

Cheers,
Stevie

kent$  cat a
stevie_db 13000 LIVE
stevie_db 13000 TEST
stevie_db 14000 DEVELOPMENT
john_db 25000 LIVE
john_db 25000 TEST
john_db 25000 DEVELOPMENT

kent$  awk '{if(!a[$1])a[$1]=$2; if (a[$1]!=$2)print $1,$3;}' a

stevie_db DEVELOPMENT
1 Like

Thanks for your help with this. However, when i try to run it (from the command line) I get the error

% cat a
stevie_db 13000 LIVE
stevie_db 13000 TEST
stevie_db 14000 DEVELOPMENT
john_db 25000 LIVE
john_db 25000 TEST
john_db 25000 DEVELOPMENT
 
 awk '{if(!a[$1])a[$1]=$2; if (a[$1]!=$2)print $1,$3;}' a

a[$1])a[$1]=$2;: Event not found
 

any ideas what I may be doing wrong?

were you executing the awk line alone or putting it into another script? are you sure you typed the command correctly?

bizarre...I can run this from bash but not from c shell.

I believe c shell requires some extra characters in order to ignore special characters (such as brackets).

Thank you very much for your help with this.