Sort a bunch of strings by an arbitrary token


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sort a bunch of strings by an arbitrary token
# 1  
Old 06-23-2011
Sort a bunch of strings by an arbitrary token

I have a bunch of strings that contain, among the tokens, the size of a file. I want sort based on this value, which is always located in the same "column" in each string, with the largest at the top. Thanks
# 2  
Old 06-23-2011
Post the sample input and desired output, please.
# 3  
Old 06-23-2011
Non-standard directory : /a/b/c/d (size 25600K) please refer to the Software Standards docs.
Non-standard directory : /e/f/g/h (size 29696K) please refer to the Software Standards docs.
Non-standard directory : /i/j/k/l (size 29696K) please refer to the Software Standards docs.
<continued...>

Sort them based on their file size largest to smallest with the largest at the top.
# 4  
Old 06-23-2011
That's the input I suppose. What do you want the output to be?
# 5  
Old 06-23-2011
In this case the two dirs with size 29696K would be listed before the one with size 25600K.
# 6  
Old 06-23-2011
Assuming that's the posted input try this...
Code:
sort -k6,6nr file

This User Gave Thanks to shamrock For This Post:
# 7  
Old 06-23-2011
Awesome, that works. Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Strange results from 'strings | sort'

Using the 'strings' command and piping the result to 'sort' is producing strange results. I get block of lines that begin with asterisks, then a block that begins with some text, then more lines that begin with asterisks. The actual content is correct - lines beginning with asterisks is the... (5 Replies)
Discussion started by: edstevens
5 Replies

2. Shell Programming and Scripting

Sort strings containing numbers

How can I sort this, first by 2nd field then by 1st field. tried sort -b -k 2,2 Input: AS11 AB1 BD34 AB10 AF12 AC2 A345 AB10 R134 AB2 456 AC10 TTT2 BD12 desired output: AS11 AB1 R134 AB2 A345 AB10 BD34 AB10 AF12 AC2 456 AC10 TTT2 BD12 (2 Replies)
Discussion started by: aydj
2 Replies

3. Shell Programming and Scripting

Sort strings with numbers

I want to sort my data first by the 2nd field then by the first field. I can't use sort -V because I don't have gnu sort and cannot install one. How do I go about this? Input: G456 KT1 34 K234 KT10 45 L2 KT2 26 H5 LAF2 28 F3 LAF2 36 Output: G456 KT1 34 L2 KT2 26 K234 KT10 45 F3... (14 Replies)
Discussion started by: aydj
14 Replies

4. UNIX for Dummies Questions & Answers

Want to sort a file which contains alphanumeric strings

I want to sort a file which contains alphanumeric string. bash-3.00$ cat abc mtng1so mtng2so mtng11so mtng9so mtng23so mtng7so hstg2so hstg9so hstg1so hstg11so hstg13so bash-3.00$ Want output like this, using one liner. hstg1so (1 Reply)
Discussion started by: Raza Ali
1 Replies

5. Shell Programming and Scripting

PERL : Sort substring occurrences in array of strings

Hi, My developer is on vacation and I am not sure if there is something which is easier for this. I have an array of strings. Each string in the array has "%" characters in it. I have to get the string(s) which have the least number of "%" in them. I know how I can get occurrences : ... (7 Replies)
Discussion started by: sinpeak
7 Replies

6. UNIX for Dummies Questions & Answers

How to sort lines by strings between ()?

Hello,everyone. I am learning some Info commands.I put all commands and their explanations in a file. This is a part of it: ESC PgUp (scroll-other-window-backward)Scroll the other window backward ESC Right (forward-word) Move forward a word ESC r (move-to-window-line) ESC TAB... (3 Replies)
Discussion started by: vic005
3 Replies

7. UNIX for Dummies Questions & Answers

Arbitrary sort orders

So, suppose I want to sort something in some arbitrary order... for example, let's say I have "grades" (actually, work evaluation results where I work) that are, from best to worst, E, A, S, D, P. So, I want to sort by a "grade" column with the E's first, then the A's, etc. Is there a reasonably... (2 Replies)
Discussion started by: treesloth
2 Replies

8. Programming

Sort ascending n strings in C

Hy guys. My English is not so good, sorry for any mistakes. I'm a bigginer in C, and I have a problem. I want to sort ascending n strings, but I can't read the strings. Here is what I've done so far: //sort ascending n strings #include <stdio.h> int main() { int n,i,j; char a; ... (8 Replies)
Discussion started by: 1/0
8 Replies

9. Shell Programming and Scripting

how to sort strings by length?

I'm trying to find the longest word in /usr/share/dict/words The first thing I can think of is to sort the content by length then it would be easy to find out, but then i realize theres no option of sort to sort by length. Could you guys please give me some help?:confused: (7 Replies)
Discussion started by: rockbike
7 Replies

10. Shell Programming and Scripting

sort() array of strings in perl

I have a perl script with an array of clients. @arr = ("The ABC Corp", "AA Corp.", "BB Corp"); If I run @a = sort (@arr); I will get @a = ("AA Corp", "BB Corp", "The ABC Corp"); but I want @a = ("AA Corp, "The ABC Corp", "BB Corp"); How do I sort array without changing... (2 Replies)
Discussion started by: photon
2 Replies
Login or Register to Ask a Question