In situations like this, I use msort. It is in many ways a work-alike for the standard sort, but it has a number of extra features, including the one we use here: a hybrid key, which is composed of alphabetic and numeric. Note that there is just the single command msort that does the work, after the setup and the verification of correctness:
$ ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 3.16.0-4-amd64, x86_64
Distribution : Debian 8.6 (jessie)
bash GNU bash 4.3.30
msort 8.53
pass-fail (local) 1.9
-----
Input data file data1:
fkdo-b-cen6 fkdo
fkdo-b-cen7 fkdo
fkdo-b-cen8 fkdo
flrp-b-an2121 flrp
flrp-b-an21 flrp
flrp-b-an22 flrp
flrp-b-an23 flrp
flrp-b-an24 flrp
flrp-b-an25 flrp
flrp-b-cen1 flrp
-----
Results:
fkdo-b-cen6 fkdo
fkdo-b-cen7 fkdo
fkdo-b-cen8 fkdo
flrp-b-an21 flrp
flrp-b-an22 flrp
flrp-b-an23 flrp
flrp-b-an24 flrp
flrp-b-an25 flrp
flrp-b-an2121 flrp
flrp-b-cen1 flrp
-----
Verify results if possible:
fkdo-b-cen6 fkdo fkdo-b-cen6 fkdo
fkdo-b-cen7 fkdo fkdo-b-cen7 fkdo
fkdo-b-cen8 fkdo fkdo-b-cen8 fkdo
flrp-b-an21 flrp flrp-b-an21 flrp
flrp-b-an22 flrp flrp-b-an22 flrp
flrp-b-an23 flrp flrp-b-an23 flrp
flrp-b-an24 flrp flrp-b-an24 flrp
flrp-b-an25 flrp flrp-b-an25 flrp
flrp-b-an2121 flrp flrp-b-an2121 flrp
flrp-b-cen1 flrp flrp-b-cen1 flrp
-----
Comparison of 10 created lines with 10 lines of desired results:
Succeeded -- files (computed) f1 and (standard) expected-output.txt have same content.
There is a price to pay for the features -- msort is slower than the standard sort.
The command msort can be found in many repositories, or, as noted in the details below, be also found at the msort home site:
Code:
msort sort records in complex ways (man)
Path : /usr/bin/msort
Version : 8.53
Type : ELF 64-bit LSB executable, x86-64, version 1 (SYSV ...)
Help : probably available with -h,--help
Home : http://billposer.org/Software/msort.html
I did a search on this, and found lots on SORT but no answer to my question.
I have a C program that fetches all of our users from Netware, and I have that it makes a file that I later include in a html as a select tag drop-down menu.
Here is what 1 line looks like:
<option... (5 Replies)
Hi,
I have a list of values from associative array from 0,..till 1.0000.
I tried various sort options; sort -g, sort -nr but it still couldnt work. In other words, the numbers are not sorted accordingly.
Please help.
Thanks. (1 Reply)
I am in the process of sorting an AutoHotkey script's contents so as to make it easier for me to find and view its nearly 200 buzzwords (when I forget which one corresponds with what phrase, which I do now and then).
About half to two-thirds of the script's key phrases correspond to locations... (7 Replies)
I need to use bash to remove duplicates without using sort first.
I can not use:
cat file | sort | uniq
But when I use only
cat file | uniq
some duplicates are not removed. (4 Replies)
I've got a disorganized list of items and quantities for each. I've been using a combination of grep and sort to find out how much to buy of each item. I'm tired of having to constantly using these commands so I've been trying to write a shell script to make it easier, but I can't figure out how... (3 Replies)
Hello
I greped some lines from an xml file and generated a new file.
but some entries are missing my table is unsorted.
e.g.
NAME="Adel" ADDRESS="Donaustr." NUMBER="2" POSTCODE="33333"
NAME="Adel" ADDRESS="Donaustr." NUMBER="2" POSTCODE="33333"
NAME="Adel" NUMBER="2" POSTCODE="33333"... (5 Replies)
URGENT HELP IS NEEDED!!
I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but
- Currently, script is not printing lines to File3.txt in order.
- Also the matching lines are not moving out of File1.txt
... (1 Reply)
I am running a command that is part of a script and this is what I am getting when it is sorted by the command:
command:
ls /tmp/test/*NDMP*.z
/tmp/test/CARS-GOLD-NET_CHROMJOB-01-XZ-ARCHIVE-NDMP.z
/tmp/test/CARS-GOLD-NET_CHROMJOB-01-XZ-NDMP.z... (2 Replies)