LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 11-01-2010, 06:08 PM   #1
dougp25
Member
 
Registered: Dec 2003
Location: Seacoast NH
Distribution: PCLinuxOS
Posts: 37

Rep: Reputation: 2
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

Last edited by dougp25; 11-01-2010 at 06:11 PM.
 
Old 11-01-2010, 06:25 PM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
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
 
Old 11-01-2010, 06:35 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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/.
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Sorting a Dictionary File dougp25 Programming 4 11-02-2010 01:29 AM
sorting a file by column AutoC Programming 6 08-07-2009 05:43 PM
Suggest a good offline dictionary-database for gnome-dictionary. abhijeetnayak Linux - Software 1 07-05-2009 05:17 PM
Help with sorting a file Yogiz Linux - Newbie 5 12-08-2007 04:41 PM
Linux File Sorting linuxgodrh Linux - General 7 08-01-2007 09:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration