Discussion:
[PLUG] Specifying numeric order to sort
Rich Shepard
2018-10-29 22:51:52 UTC
Permalink
I want to sort the following file in reverse numeric order (highest number
first, sequentially decreasing to lowest number). I've tried specifying -g,
-n, and -h for the numeric sort order and none seem to work for me.

The command 'sort -n -r -k 3 number-samples-per-site.txt -o sorted' is an
example. And, the reverse option is ignored when I specify a numeric format.
(Whether the -k option has a space before the 3 makes no difference here.)

I'm not seeing what I'm missing.

---8<----------------------------
site_nbr | site_name | count
----------+-----------------------------------------------------------------+-------
10625 | Clackamas R. at Carver | 1
10483 | Beaverton Creek/downstream of Tektronix | 1
11757 | South Yamhill R. upstream of Whiteson Landfill | 1
10486 | Cedar Mill Creek at Hwy 26 (Cedar Mill) | 1
11758 | South Yamhill R. opposite side from Whiteson Landfill | 1
10351 | Willamette R. at Adair water intake | 1
11759 | South Yamhill R. downstream of Whiteson Landfill | 1
10468 | Fanno Creek at Durham Station (Durham) | 1
10865 | Deep Creek at Hwy 224 Bridge (Barton) | 1
10459 | Tualatin R. at Hwy 210 (Scholls) | 1
15431 | 1670 Thornton Lake Place/Dick Berne | 1
10360 | Clackamas R. at Hwy 99E (Gladstone) | 1
10340 | Willamette R. at I-5 (Wilsonville) | 1
10335 | Willamette R. at Staff Jennings Marina | 1
15417 | 1436 Harder Lane/E. E. Eckart | 2
10350 | Willamette R. at Albany (eastbound Hwy 20 bridge) | 2
15438 | 451 NW Quarry Road/P. Vollstedt Pasture | 2
15428 | 960 NW ones/Dick Housden | 2
10366 | South Santiam R. Hwy 226 (Crabtree) | 2
15415 | 1434 Springhill Road/S. L. Dalesky | 2
10348 | Willamette R. at Buena Vista Ferry | 2
15426 | 825 NW Ridders/Geo. Bryson | 2
16679 | Woodburn Landfill Monitoring Well 13B (L-10) | 2
15418 | 451 NW Quarry Road/Phyllis Vollstedt | 2
15423 | 710 E Thornton Lake Road/R.H. Mealey | 2
15413 | 724 S. Nebergall Loop/Bob Whitehead | 2
10339 | Willamette R. at Canby Ferry | 2
15420 | 146 NE Cloverdale/Tom Aasum | 2
15424 | 905 NE Springhill Road/Golf Club | 2
10792 | North Santiam R. at Greens Bridge | 2
10555 | Willamette R. at Marion Street (Salem) | 2
10794 | North Santiam at Mehama Bridge | 2
10347 | Willamette R. at South R. Road (Independence) | 2
15419 | 880 NE Cherry Lane/Tom Hughson | 2
15435 | 171 Creswell Lane/im Moore | 2
15416 | 1440 Shady Lane/Lynn Peters | 2
16675 | Woodburn Landfill Monitoring Well 9 (L-4) | 3
16704 | New Woodburn Landfill Monitoring Well L-13 (Monitoring Well -F) | 3
16695 | Woodburn Landfill Monitoring Well 12C (L-3) | 3
16700 | New Woodburn Landfill Monitoring Well L-14 (Monitoring Well -E) | 3
16680 | Woodburn Landfill Monitoring Well 14 (L-6) | 3
10460 | Tualatin R. at Farmington Road | 3
15784 | Short Mountain Landfill Monitoring Well leachate lagoon | 4
10777 | South Santiam R. at Waterloo Bridge | 4
10361 | Molalla R. at Hwy 99E (Canby) | 4
16696 | Woodburn Landfill Monitoring Well L-12 | 4
16703 | New Woodburn Landfill Monitoring Well L-5 (Monitoring Well -A) | 4
16692 | Woodburn Landfill Monitoring Well 25 (P-25) | 4
10342 | Willamette R. at Hwy 219 (new Newberg bridge) | 4
16705 | Monitoring Well L-9 | 4
14326 | Brown's Island Landfill Monitoring Well 10B | 5
14331 | Brown's Island Landfill Monitoring Well 12B | 5
11180 | Calapooia R. at Queen Road | 5
14436 | Coffin Butte's leachate Lagoon | 5
10928 | North Yamhill R. at Hwy 99W | 6
14322 | Brown's Island Landfill Monitoring Well 8C | 6
16699 | Woodburn Landfill leachate Lagoon | 6
16677 | Woodburn Landfill Monitoring Well L-2 | 6
10359 | Willamette R. at Hwy 126 (Springfield) | 6
14314 | Brown's Island Landfill Monitoring Well 5 | 7
16697 | Monitoring Well L-7 | 7
10456 | Tualatin R. at Boones Ferry Road | 7
11233 | Clackamas R. at High Rocks (Old Hwy 213) | 8
16701 | Monitoring Well L-15 | 8
31545 | Willamette R. at Hebb Park Boat Ramp | 9
10948 | South Yamhill R. at Hwy 99W (McMinnville) | 9
10917 | Pudding R. at Hwy 99E (Aurora) | 22
10332 | Willamette R. at SP&S RR Bridge (Portland) | 25
10833 | Willamette R. 0.5 miles downstream of Tualatin R. | 36
34198 | Willamette R. at Storm Park boat dock | 36
10376 | McKenzie R. at Coburg Road | 40
31731 | Willamette R. at Wallace Marine Park boat ramp | 44
27986 | Middle Fork Willamette R above Hills Crk at USGS Gage 14144800 | 44
10355 | Willamette R. at Hwy 99E (Harrisburg) | 46
10821 | Willamette R. at St. Johns Bridge | 48
10379 | Coast Fork Willamette R. at Hwy 58 | 50
29044 | Willamette R. at Greenway bike bridge/Eugene | 52
10344 | Willamette R. at Wheatland Ferry | 58
26339 | Willamette R. upstream of Newberg Bridge at Rogers Landing | 59
29043 | Willamette R. at Willamette Park boat ramp/Corvallis | 60
10386 | Middle Fork Willamette R. at Jasper Bridge | 66
10775 | Santiam R. at Jefferson Bridge | 67
-------8<------------------------------------------

TIA,

Rich
David Fleck
2018-10-29 23:39:51 UTC
Permalink
On Mon, 2018-10-29 at 15:51 -0700, Rich Shepard wrote:
>
The command 'sort -n -r -k 3 number-samples-per-site.txt -o sorted' is an
> example. And, the reverse option is ignored when I specify a numeric format.
> (Whether the -k option has a space before the 3 makes no difference here.)
>
> I'm not seeing what I'm missing.

I think you're missing the '-t' option. Try

sort -n -r -t '|' -k 3 number-samples-per-site.txt -o sorted
Rich Shepard
2018-10-30 00:36:10 UTC
Permalink
On Mon, 29 Oct 2018, David Fleck wrote:

> I think you're missing the '-t' option. Try
> sort -n -r -t '|' -k 3 number-samples-per-site.txt -o sorted

Thanks, David. I looked at the -t option, saw the spaces between columns
and ignored the pipe as the separator.

Best regards,

Rich
Russell Senior
2018-10-30 03:38:53 UTC
Permalink
> I want to sort the following file in reverse numeric order (highest number
> first, sequentially decreasing to lowest number). I've tried specifying -g,
> -n, and -h for the numeric sort order and none seem to work for me.

I want to take this opportunity to note that I am personally
responsible for the -g option to GNU sort. It is extra slow, but once
upon a time in the early 1990s I needed it, and I collaborated on the
patch that was eventually applied. That's all I wanted to say.
Loading...