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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using csh / awk / sed to compare database sizes in a txt file
# 1  
Old 09-16-2011
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)

Code:
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

Last edited by radoulov; 09-16-2011 at 01:02 PM.. Reason: Code tags, please!
# 2  
Old 09-16-2011
Code:
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

This User Gave Thanks to sk1418 For This Post:
# 3  
Old 09-19-2011
Quote:
Originally Posted by sk1418
Code:
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


Thanks for your help with this. However, when i try to run it (from the command line) I get the error
Code:
% 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?

Last edited by Scott; 09-19-2011 at 11:03 AM.. Reason: Please use code tags
# 4  
Old 09-19-2011
were you executing the awk line alone or putting it into another script? are you sure you typed the command correctly?
# 5  
Old 09-19-2011
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh scripting SSH to Compare File Sizes

Hello, I currently have very little experience with Shell scripting and trying to create a script for the purpose of collecting the size of a couple sizes on 4 different Hosts. The Idea is to collected the information from the files in which the script is kicked off on, store the values into... (17 Replies)
Discussion started by: Abstract3000
17 Replies

2. Shell Programming and Scripting

Awk, sed, shell all words in INPUT.txt find in column1 of TABLE.txt and replce with column2 in

Hi dears i have text file like this: INPUT.txt 001_1_173 j nuh ]az 001_1_174 j ]esma. nuh ]/.xori . . . and have another text like this TABLE.txt j j nuh word1... (6 Replies)
Discussion started by: alii
6 Replies

3. Shell Programming and Scripting

Converting txt file into CSV using awk or sed

Hello folks I have a txt file of information about journal articles from different fields. I need to convert this information into a format that is easier for computers to manipulate for some research that I'm doing on how articles are cited. The file has some header information and then details... (8 Replies)
Discussion started by: ksk
8 Replies

4. Shell Programming and Scripting

Script to compare file sizes

I need to write a bash script larger X Y that compares the sizes of two specified files X and Y, and reports which file is larger. For example, if X is larger, the output should be "File X is larger", while if Y is larger, the output should be "File Y is larger". If the files are exactly the... (3 Replies)
Discussion started by: julia_21436
3 Replies

5. UNIX for Dummies Questions & Answers

Compare two file sizes.

Hi everyone! I need to compare two file sizes. One of them (size) will be stored in a flat file and the other coming from a listed file. I can now get the first file size using: SIZE=`ls -l $DOCTYPE | awk '{print $5}'` 1. How can I store this value in a flat file? 2. How... (2 Replies)
Discussion started by: mrreds
2 Replies

6. HP-UX

compare file percent sizes

I need to get a file size and compare it to a previous day file size. If it's larger or smaller by 50 percent I'll replace the new with the old. I know how to get the file sizes but do not know how to calculate if it's 50 percent difference. Thanks for your help. (2 Replies)
Discussion started by: jkuchar747
2 Replies

7. Shell Programming and Scripting

how to compare file sizes

hi ls -l * | sed 's/\+/ /g' | cut -f5 -d " " >out1 ls -l * | sed 's/\+/ /g' | cut -f5 -d " " >out2 diff out1 out2 i tried this it will work fine and i can see difference but i need a script which should neglect, if the difference b/w files is small and it should display... (5 Replies)
Discussion started by: revenna
5 Replies

8. Shell Programming and Scripting

Script to check and report database file sizes...

Need help for a script to check and report database file sizes. (2 Replies)
Discussion started by: marconi
2 Replies

9. Shell Programming and Scripting

txt file to oracle database

hiya, i have a query: i want to read a file which contains: 2005/02/21 16:56:54.301: 111 PS (200, 10) sent <log instrument="FXA.ROSS"... (9 Replies)
Discussion started by: jorhul
9 Replies

10. Shell Programming and Scripting

compare file sizes

Is there a command that will return the name of the largest file within a directory? If so, can I set the returned filename into a variable? (4 Replies)
Discussion started by: joli
4 Replies
Login or Register to Ask a Question