1

I have a data.txt file

1   2    3     4       5       6
cat data.txt
17 245 1323 17.7777 10.2222 61.1111
19 232 1232 19.9999 19.9999 68.8888
13 133 1233 13.3333 13.3333 63.3333
17 177 1678 17.7777 17.7777 69.9999
12 122 2325 12.2222 11.333  64.4444
18 245 1323 18.8888 12.4444 68.8888
12 222 1222 12.2222 19.9999 61.1111 
14 245 1323 14.4444 13.5555 68.8888

I would like the find all the values sequentially from 12.2222 in column 4 to 18.8888. Answer:

echo ${minValsCol4[@]}
12.2222 13.3333 14.4444 17.7777 18.8888

And the values sequentially from 63.3333 in column 6 to 68.8888. Answer:

echo ${minValsCol6[@]}
63.3333 64.4444 68.8888

Any solution in awk? Thanks.

user3652962
  • 453
  • 1
  • 4
  • 13
  • You haven't marked any of your previous questions as answered (http://stackoverflow.com/questions/23822564/bash-find-nearest-next-value-forward-and-backward and http://stackoverflow.com/questions/23842261/alternative-to-readarray-because-it-does-not-work-on-mac-os-x). Is there something about the answers you've been getting that makes none of them work for you? – Ed Morton May 24 '14 at 18:00

1 Answers1

3

Using awk and sort -nu:

awk -v col=4 -v start=12.2222 -v end=18.8888 '$col>=start && $col<=end{
              print $col}' data.txt | sort -nu

12.2222
13.3333
14.4444
17.7777
18.8888
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    oops!! almost the same idea and implementation!!, +1, and mine is pending to be removed... – Kent May 24 '14 at 15:19
  • Ditto. Mine was `sort -unk4,4 file | awk -v low='12.2222' -v high='18.8888' '$4>high{exit};$4>=low{print $4}'` – user000001 May 24 '14 at 15:20