From: Atropo on
Hi all.

I got this file from sql output
dates_out.txt:
26-03-2009 P
26-03-2009 B
26-03-2009 R
26-03-2009 L
26-03-2009 O

i would like to compare if there is differences in the first field
only. they were dates but now the're only chars. i'm not quite
sure about the uniq -f 2. it shows 26-03-2009 P

if any is different then send a mail
From: Janis Papanagnou on
Atropo schrieb:
> Hi all.
>
> I got this file from sql output
> dates_out.txt:
> 26-03-2009 P
> 26-03-2009 B
> 26-03-2009 R
> 26-03-2009 L
> 26-03-2009 O
>
> i would like to compare if there is differences in the first field
> only. they were dates but now the're only chars. i'm not quite
> sure about the uniq -f 2. it shows 26-03-2009 P
>
> if any is different then send a mail

You mean if there is more than one date in column 1 you want
some action?

The following program prints the different types of values in
field 1...

awk '{a[$1]}END{print length(a)}' dates_out.txt

If you set the exit-code appropriately you can trigger sending
a mail or whatever...

awk '{a[$1]}END{exit(length(a)!=1)}' dates_out.txt ||
{ echo Failed | mail -s Huhu you(a)org ;}


Janis
From: Atropo on
On Aug 4, 11:06 am, Janis Papanagnou <janis_papanag...(a)hotmail.com>
wrote:
> Atropo schrieb:
>
> > Hi all.
>
> > I got this file from sql output
> > dates_out.txt:
> > 26-03-2009 P
> > 26-03-2009 B
> > 26-03-2009 R
> > 26-03-2009 L
> > 26-03-2009 O
>
> > i would like to compare if there is differences in the first field
> > only.   they were dates but now the're only chars.   i'm not quite
> > sure about the uniq -f 2.   it shows 26-03-2009 P
>
> > if any is different then send a mail
>
> You mean if there is more than one date in column 1 you want
> some action?
exactly

> The following program prints the different types of values in
> field 1...
>
>    awk '{a[$1]}END{print length(a)}' dates_out.txt
>
/usr/xpg4/bin/awk '{a[$1]}END{print length(a)}' dates_out.txt
the output is 0.

but first, why length(a), how could this evaluate differences?

> If you set the exit-code appropriately you can trigger sending
> a mail or whatever...
set the exit-code appropriately --- not sure what you mean.

>
>    awk '{a[$1]}END{exit(length(a)!=1)}' dates_out.txt ||
>      { echo Failed | mail -s Huhu you(a)org ;}
>
> Janis

I really appreciate your effort to help me janis, but i may be on a
little lower place of knowlegde. I'm RTFM. but i'm not there yet

From: Greg Russell on
"Atropo" <lxvasquez(a)gmail.com> wrote in message
news:7e95d0dc-b75d-4152-a0b9-320da113e641(a)d8g2000yqf.googlegroups.com...

> I got this file from sql output
> dates_out.txt:
> 26-03-2009 P
> 26-03-2009 B
> 26-03-2009 R
> 26-03-2009 L
> 26-03-2009 O
>
> i would like to compare if there is differences in the first field
> only. they were dates but now the're only chars. i'm not quite
> sure about the uniq -f 2. it shows 26-03-2009 P

Read the man page: what part of "Discard all but one of successive
identical lines ..." don't you understand? Because you're only comparing the
first field which is identical for every line, only the first line is
returned.


From: Kenny McCormack on
In article <i3bvmc$c31$1(a)speranza.aioe.org>,
Janis Papanagnou <janis_papanagnou(a)hotmail.com> wrote:
>Atropo schrieb:
>> Hi all.
>>
>> I got this file from sql output
>> dates_out.txt:
>> 26-03-2009 P
>> 26-03-2009 B
>> 26-03-2009 R
>> 26-03-2009 L
>> 26-03-2009 O
>>
>> i would like to compare if there is differences in the first field
>> only. they were dates but now the're only chars. i'm not quite
>> sure about the uniq -f 2. it shows 26-03-2009 P
>>
>> if any is different then send a mail
....
>The following program prints the different types of values in
>field 1...
>
> awk '...

Yes, it looks like 'uniq' has options to skip the first 'n' fields or
the first 'n' chars (if I am reading the man page correctly), but not to
skip fields at the end of the line.

So, an AWK (or Perl or Python or C or C++ or Ruby or ...) solutions
seems to be needed. AFAICT, Janis's AWK idea looks right.

--
Faced with the choice between changing one's mind and proving that there is
no need to do so, almost everyone gets busy on the proof.

- John Kenneth Galbraith -