1

Consider the following foo.dat file with 11 columns:

  893    1  754  946  193   96   96     293.164     293.164     109.115     70.8852
  894    1  755  946  192   95   96     291.892     292.219     108.994      70.821
  895    1  755  947  193   95   97     290.947     291.606     109.058     70.5709
  896    1  755  947  193   95   97     290.002     290.663     109.122     70.5053
  897    1  755  948  194   95   98     289.057     290.057     109.187     70.2532
  898    1  754  949  196   96   99     288.444     289.456      109.44          70
  899    1  754  950  197   96  100     287.501     288.862     109.506     69.7458
  900    1  754  949  196   96   99     286.559     287.578     109.573     69.8637

I'd like to filter the columns 11 and 9 and print only these on a file, but in ascending order on 1st new column, that is, after printing 11 and 9 columns, sort the output by numerical rule.

I tried

awk  -F' ' '{printf "%-12s%-12s\n", $11, $9}' foo.dat | sort -g 

but the output is strange around 70. It is

70.2532 290.057
70 289.456
70.5053 290.663

Why 70 is not before 70.2532? Looks like . is being ignored.

5

I suspect you have a locale using a comma as decimal separator. This should fix that issue:

awk  -F' ' '{printf "%-12s%-12s\n", $11, $9}' foo.dat | LC_ALL=C sort -g
  • 1
    You are completely right about the locale. I never had imaged this could be the solution. It works like a charm. Thanks so much. – Sigur Apr 7 '17 at 23:12

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.