Operating System - HP-UX
1847087 Members
5898 Online
110262 Solutions
New Discussion

Re: Shell script to compare fields in columns

 
SOLVED
Go to solution
R.O.
Esteemed Contributor

Shell script to compare fields in columns

Hi,

I have a file with two columns of numeric data. I want to compare column1-field1 with column2-field1, column1-field2 with column2-field2...etc. If I see that, in example, column1-field1 is different to column2-field1 I want to do the same test five minutes later and if the situation is the same, then do an action (for example, send a mail).
I want to put the script in the crontab.

Any ideas of how to do it??

Regards,
"When you look into an abyss, the abyss also looks into you"
4 REPLIES 4
Muthukumar_5
Honored Contributor
Solution

Re: Shell script to compare fields in columns

Can you give an example here? Can you elaborate more on "If I see that, in example, column1-field1 is different to column2-field1 I want to do the same test five minutes later"

You can use awk to compare fields as simply as,

echo "12 13" | awk '{ if ( $1 > $2) { print "Field1 is bigger";} else { print "Field2 is bigger";}}'

-Muthu
Easy to suggest when don't know about the problem!
Steve Steel
Honored Contributor

Re: Shell script to compare fields in columns

Hi

Please give a few lines of data to test with

For scripting help
www.shelldorado.com


Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Arturo Galbiati
Esteemed Contributor

Re: Shell script to compare fields in columns

Hi,
you want to stop as soon as the values are different or anyway check all file?
Please explain better what you need.
Rgds,
Art
Arturo Galbiati
Esteemed Contributor

Re: Shell script to compare fields in columns

Hi,
do you want to stop to check the values ina file at the first difference, or you want to continue till the end of teh file?
Please, specify better what you need.
Art