Gathering info on one line

Hi all again,

here is the file i am working on :

GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:04
GREIMBAJ00;BAN_CAV;Loader.sh;2003/06/13;17:04:06
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:11
GREIMBAJ00;BAN_PAK;Loader.sh;2003/06/13;17:04:18
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:16
GREIMBAJ00;PER_COT;Loader.sh;2003/06/13;17:04:21
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:25
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:04:35
GREIMBAJ01;BAN_CAV;Traitement.sh;2003/06/13;17:05:03
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:19:56
GREIMBAJ02;BAN_PAK;Traitement.sh;2003/06/16;09:20:00
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:03
GREIMBAJ02;BAN_PAK;Delete.sh;2003/06/16;09:20:05
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:34
GREIMBAJ04;BAN_LIE;Pretraitement.sh;2003/06/16;09:27:37
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:27:39
GREIMBAJ04;BAN_RAV;Traitement.sh;2003/06/16;09:28:23

Here is what i want to do :

When 2 lines are identical (excepting the hour), for instance :

GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18
GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:25

i would like to obtain the following result :

GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18;17:04:25

But I dont have any idea on how to make this working...:rolleyes:

Any help would be appreciated !

Thanks

Regards

Howard

FYI, it's easier to follow what's going on if you just continue the thread where you started it:

sort -ut\; -k 1,2 -k 3,4 infile

However, this gives the line with the earliest time, not the latest...

Oups sorry about that...i though this post hadnt any link with the other one....

Anyway, i dont think i had been very clear on my problem....i want to obtain the following result :

GREIMBAJ00;PER_COT;Traitement.sh;2003/06/13;17:04:18;17:04:25

As you can notice, i would like to have the 2 "hour" fileds pasted together and separated by a ";".

As you said, the command you gave only keep the ealiest hour...

Any other idea?

Regards

Howard

You would have to write a script -
read line one - use cut or awk (or some other command to edit the line) to take the first four fields and compare saved line.

(Note, first line in file would not be compared just saved)
read line one
save as compareline
read line two
compare line two against saved line (first four fields only)
if the same, write/print saved line and last field of line two
else
write/print compareline
save line two as compare line
loop

This should work except for when line three is the same as line two...then you will end up with two lines that should have been one line with three different times.

I can't think of a command that will do it on it's own although some of the folks here can do amazing things with sed, awk, and others.

Here's one solution, using awk:

sort -t\; yourFile > TMP_00

holdField=`head -n 1 TMP_00 | awk -F";" '{print $1";"$2";"$3";"$4}'`

while read LINE
do
 Field=`echo $LINE | awk -F";" '{print $1";"$2";"$3";"$4}'`
 if [ $Field == $holdField ]; then
  allTimes=$allTimes`echo $LINE | awk -F";" '{print ";"$5}'`
 else
  echo $holdField$allTimes >> resultFile
  holdField=$Field
  allTimes=`echo $LINE | awk -F";" '{print ";"$5}'`
 fi
done < TMP_00

echo $holdField$allTimes >> resultFile
rm TMP_00

:slight_smile: That is exactly what i was looking for!

Thank you very much to you!

Regards

Howard;)