|
From: | Eric Blake |
Subject: | bug#33371: RFC: option for numeric sort: ignore-non-numeric characters |
Date: | Tue, 13 Nov 2018 20:44:32 -0600 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 |
On 11/13/18 8:32 PM, L A Walsh wrote:
I have a bunch of files numbered from 1-over 2000 without leading zeros (think rfc's)... They have names with a non-numeric prefix & suffix around the number. It would be nice if sort had the option to ignore non-numeric data and only sort on the numeric data in the 'lines'/'files'. Yeah, I can renumber and rename them all, but I just wanted an instant command that could sort numeric values even if embedded in a line, where the "field" was determined by the start/stop of numeric characters. Or is there an options for this already, and my manpage out of date?
Without ACTUAL data to experiment with, it's much harder for anyone else to propose a solution that will work with your specific data.
But one quick approach comes to mind: decorate-sort-undecorate: sed 's/^\([^0-9]*\)\([0-9]*\)/\2 \1\2/' < myinput \ | sort -k1,1n | sed 's/^[0-9]* //' > myoutput -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
[Prev in Thread] | Current Thread | [Next in Thread] |