LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Sorting a Dictionary File (https://www.linuxquestions.org/questions/programming-9/sorting-a-dictionary-file-841776/)

dougp25 11-01-2010 06:08 PM

Sorting a Dictionary File
 
I have this dictionary file that has this format:

SUBSTITUTE_VALUE, Real Value
SUBSTITUTE_VALUE_2, Real Big Value
SUBSTITUTE_VALUE_HECL, Hardware Abstract
SUBSTITUTE_V, Valley Mem

I want to sort this file so the LONGEST Substitute Values are listed at the top ( so SUBSTITUTE_VALUE_HECL would be first in the list). Obviously I want to keep the related values tagging along with them, so the whole first line would be
SUBSTITUTE_VALUE_HECL, Hardware Abstract

Playing with sort
This has me pretty close:
sort dict.file -k1.1n,1

AnanthaP 11-01-2010 06:25 PM

So you want to sort by the length of the first field. I would use awk to generate the length.

(1) use awk to copy the output file thus: nLength, Field1, Field1
(2) Sort the output
(3) Use awk again to delete the first field.

OK

unSpawn 11-01-2010 06:35 PM

Please post your thread once and in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread should be closed or merged because it is a duplicate of http://www.linuxquestions.org/questi...y-file-841773/.


All times are GMT -5. The time now is 05:02 PM.