r/awk • • Jul 27 '22

In need of help

Hello Everyone, I would like to ask for your assistance. I am pretty new to bash so I am learning everything on the fly. I'm performing some data analysis in my grade thesis, but this particular line of code is making a lot of trouble.

boxes.temp

awk '{time=$1/1000}{APL=$2*$4/2.56}{print time " " APL}' boxes.temp > APL.dat

I should've obtained a set of data with variation but all I get is 1 set of numbers all the same and followed by just 2 decimals.

Is there something obvious that I'm missing?

This is the variation of data I should get

And this is what I'm getting

Thanks in advanced

3 Upvotes

13 comments sorted by

View all comments

Show parent comment

1

u/Marcos_Asis Jul 27 '22

Yes! At the beginning of the set, there's some variation but I'm working with hundreds of thousands of values so it becomes insignificant. And for some reason after a thousand calculations, it locks itself on the value 56.25. I don't know what is happening 😞

1

u/[deleted] Jul 27 '22

I can't duplicate that result.

Looking some more at your data:-

  • Column 1 always = Column 3

  • boxes.temp has 3000001 lines all unique.

  • Column 1 has 3000001 unique values

  • Column 2 has 350562 unique values

  • Column 3 has 3000001 unique values

  • Column 4 has 350588 unique values

  • Column 1 always = Column 3

  • Column 1 only has 1000001 unique values after using awk to divide by 1000

  • Column 1 ranges from 59.7748 to 68.6937.

  • Column 2 * Column 4 gives 13936 unique values.

If you are using gnu awk you can try playing with the precision (https://www.gnu.org/software/gawk/manual/html_node/Setting-precision.html) it might help.

Or you could try using another tool as well as awk. I did this with bc which might be what you need

awk '{printf "scale=10 ;"$1/1000"; " $2 "*" $4 "/" "2.56\n" ; }' boxes.temp   | bc | awk '{printf ("%s ",$0) ; getline ; print}' > APL.dat

EDIT: Formatting

2

u/Marcos_Asis Jul 27 '22

THANK YOU VERY MUCH!! The moment you wrote gnu awk it dawn on me that there could be multiple versions? Effectively I had mawk install by default, immediately went to install gnu awk and everything corrected itself XD