0

I have about 2000 files in the following format:

FILEA: WHWH-19975612.txt

0.1   70  30
0.01  70  32
0.9   72  32
...

FILEB: WHWH-20004526.txt

0.2   70 30
0.001 70 32
1.0   72 32
...

Desired output

0.2  70 30  WHWH-20004526
0.01 70 32  WHWH-19975612
1.0  72 32  WHWH-20004526
...

Doing this will keep track of files where larger values are present, which I can call for further processing.

0

As long as the number of files fits into one call to awk, you can do:

awk '{ if ($1 > maxvalues[$2" "$3]) { 
         maxvalues[$2" "$3]=$1; 
         maxfiles[$2" "$3]=FILENAME; 
       }
     } 
     END { 
       for (i in maxvalues) printf "%-4s %5s %s\n", maxvalues[i], i, maxfiles[i] 
    }' \
    *

I created a test set of files with your sample data, and then by running:

for((i=20004527;i<20006526;i++))
do 
  cp WHWH-20004526.txt WHWH-${i}.txt
done

... to create ~2000 data files to work with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.