sort not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sort not working
# 1  
Old 09-04-2012
sort not working

// AIX 5.3 & 6.1

I am trying to sort by size.
HTML Code:
# fuser -OdV /tmp | sort -n -t= -k 3,3
But, it gives me like below.
HTML Code:
inode=3502   size=193106       fd=1    
inode=3502   size=193106       fd=2    
inode=3513   size=139474       fd=2    
inode=3511   size=261016       fd=1    
inode=3502   size=193106       fd=2    
inode=3502   size=193106       fd=2    
inode=3502   size=193106       fd=2    
inode=3502   size=193106       fd=2    
inode=3512   size=103334       fd=2    
inode=3510   size=274318       fd=2    
inode=3502   size=193106       fd=2    
inode=3513   size=139474       fd=1    
inode=3513   size=139474       fd=2    
inode=3510   size=274318       fd=1    
inode=3510   size=274318       fd=2    
inode=3510   size=274318       fd=2  
Please advise how to sort by 'size'.
# 2  
Old 09-04-2012
Something odd with your version of sort, I can't duplicate it with any version I try, even the cheap/bad ones.

Maybe if you mangle the output into something a little simpler... Change equals and tabs into spaces, and squeeze multiple spaces into one so sort works with default settings.

Code:
$ command | tr -s ' \t=' ' ' | sort -n -k 4

inode 3512 size 103334 fd 2
inode 3513 size 139474 fd 1
inode 3513 size 139474 fd 2
inode 3513 size 139474 fd 2
inode 3502 size 193106 fd 1
inode 3502 size 193106 fd 2
inode 3502 size 193106 fd 2
inode 3502 size 193106 fd 2
inode 3502 size 193106 fd 2
inode 3502 size 193106 fd 2
inode 3502 size 193106 fd 2
inode 3511 size 261016 fd 1
inode 3510 size 274318 fd 1
inode 3510 size 274318 fd 2
inode 3510 size 274318 fd 2
inode 3510 size 274318 fd 2

$

# 3  
Old 09-04-2012
Code:
VirtualBox:~/Desktop$ sort -t$'\t' -k2,2 temp.txt
inode=3512      size=103334       fd=2    
inode=3513      size=139474       fd=1    
inode=3513      size=139474       fd=2    
inode=3513      size=139474       fd=2    
inode=3502      size=193106       fd=1    
inode=3502      size=193106       fd=2    
inode=3502      size=193106       fd=2    
inode=3502      size=193106       fd=2    
inode=3502      size=193106       fd=2    
inode=3502      size=193106       fd=2    
inode=3502      size=193106       fd=2    
inode=3511      size=261016       fd=1    
inode=3510      size=274318       fd=1    
inode=3510      size=274318       fd=2
inode=3510      size=274318       fd=2    
inode=3510      size=274318       fd=2

# 4  
Old 09-04-2012
That will not work when number of digits differs, though...
# 5  
Old 09-04-2012
Quote:
Originally Posted by Corona688
That will not work when number of digits differs, though...
You are right. I didn't assume different scenarios.
# 6  
Old 09-04-2012
Quote:
Originally Posted by Corona688
Something odd with your version of sort, I can't duplicate it with any version I try, even the cheap/bad ones.

Maybe if you mangle the output into something a little simpler... Change equals and tabs into spaces, and squeeze multiple spaces into one so sort works with default settings.

Code:
$ command | tr -s ' \t=' ' ' | sort -n -k 4

inode 3512 size 103334 fd 2
inode 3513 size 139474 fd 1
inode 3513 size 139474 fd 2
inode 3513 size 139474 fd 2
inode 3502 size 193106 fd 1
inode 3502 size 193106 fd 2
inode 3502 size 193106 fd 2
inode 3502 size 193106 fd 2
inode 3502 size 193106 fd 2
inode 3502 size 193106 fd 2
inode 3502 size 193106 fd 2
inode 3511 size 261016 fd 1
inode 3510 size 274318 fd 1
inode 3510 size 274318 fd 2
inode 3510 size 274318 fd 2
inode 3510 size 274318 fd 2

$

HTML Code:
 fuser -OdV /tmp| tr -s ' \t=' ' ' | sort -n -k 4
That is odd ......

I got this still.
PHP Code:
inode=3511   size=261016       fd=2    
inode
=3511   size=261016       fd=2    
inode
=3511   size=261016       fd=2    
inode
=3512   size=103334       fd=2    
inode
=3512   size=103334       fd=2    
inode
=3512   size=103334       fd=2    
inode
=3510   size=274318       fd=2    
inode
=3502   size=193106       fd=2    
inode
=3502   size=193106       fd=1    
inode
=3502   size=193106       fd=2    
inode
=3502   size=193106       fd=2    
inode
=3502   size=193106       fd=2    
inode
=3502   size=193106       fd=2    
inode
=3502   size=193106       fd=2    
....... 
and a warning...
PHP Code:
sortWarningA newline character was added to the end of the input.
 
8061064 13697166 21364740 23199978 27590776 30998546 34668546 39911624 41681096 46661728 55967902 63307820 63439012 3015142 6488484 
# 7  
Old 09-04-2012
Try
Code:
fuser -OdV /tmp 2>&1 | sort -n -t= -k 3,3

(fuser appears to output to stderr, at least on AIX 5.3)
These 2 Users Gave Thanks to CarloM For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Is this sort working as it is supposed to be? A bit confused whether it is sorting correctly or not

Hi, Below is the sample file: $ cat x.txt MDSYS|OGIS_GEOMETRY_COLUMNS|TABLE MDSYS|OGIS_SPATIAL_REFERENCE_SYSTEMS|TABLE MDSYS|SDO_IDX_TAB_SEQUENCE|SEQUENCE MDSYS|SDO_PREFERRED_OPS_USER|TABLE MDSYS|SDO_ST_TOLERANCE|TABLE MDSYS|SDO_TOPO_DATA$|TABLE MDSYS|SDO_TOPO_RELATION_DATA|TABLE... (4 Replies)
Discussion started by: newbie_01
4 Replies

2. UNIX for Beginners Questions & Answers

Difference of Sort -n -k2 -k3 & Sort -n -k2,3

Hi, Could anyone kindly show me a link or explain the difference between sort -n -k2 -k3 & sort -n -k2,3 Also, if I like to remove the row with repetition at both $2 and $3, Can I safely use sort -u -k2 -k3 Example; 100 20 30 100 20 30 So, both $2 and $3 are same and I... (2 Replies)
Discussion started by: Indra2011
2 Replies

3. Shell Programming and Scripting

Sort based on column 1, not working with awk

Hi Guru, I need some help regarding awking the output so it only show the first line (based on column) of each row. So If column has 1, three row, then it only show the first line of that row, based on similar character in column 1. So i am trying to achieve a sort, based on column one and... (3 Replies)
Discussion started by: Junes
3 Replies

4. Shell Programming and Scripting

Sort help: How to sort collected 'file list' by date stamp :

Hi Experts, I have a filelist collected from another server , now want to sort the output using date/time stamp filed. - Filed 6, 7,8 are showing the date/time/stamp. Here is the input: #---------------------------------------------------------------------- -rw------- 1 root ... (3 Replies)
Discussion started by: rveri
3 Replies

5. Shell Programming and Scripting

Why is sort not working properly here ?

Platform: RHEL 5.4 In the below text file I have strings like following. $ cat /tmp/mytextfile.txt DISK1 DISK10 DISK101 DISK102 DISK103 DISK104 DISK105 DISK106 DISK107 DISK108 DISK109 DISK110 DISK111 DISK112 DISK113 DISK114 (8 Replies)
Discussion started by: kraljic
8 Replies

6. Shell Programming and Scripting

Help with sort word and general numeric sort at the same time

Input file: 100%ABC2 3.44E-12 USA A2M%H02579 0E0 UK 100%ABC2 5.34E-8 UK 100%ABC2 3.25E-12 USA A2M%H02579 5E-45 UK Output file: 100%ABC2 3.44E-12 USA 100%ABC2 3.25E-12 USA 100%ABC2 5.34E-8 UK A2M%H02579 0E0 UK A2M%H02579 5E-45 UK Code try: sort -k1,1 -g -k2 -r input.txt... (2 Replies)
Discussion started by: perl_beginner
2 Replies

7. Shell Programming and Scripting

Why is sort -k not working all the time?

I have a script that puts a list of files in two separate arrays: First, I get a file list from a ZIP file and fill `FIRST_Array()` with it. Second, I get a file list from a control file within a ZIP file and fill `SECOND_Array()` with it while read length date time filename ... (8 Replies)
Discussion started by: alan
8 Replies

8. UNIX for Advanced & Expert Users

Script to sort the files and append the extension .sort to the sorted version of the file

Hello all - I am to this forum and fairly new in learning unix and finding some difficulty in preparing a small shell script. I am trying to make script to sort all the files given by user as input (either the exact full name of the file or say the files matching the criteria like all files... (3 Replies)
Discussion started by: pankaj80
3 Replies

9. Shell Programming and Scripting

How to Sort Floating Numbers Using the Sort Command?

Hi to all. I'm trying to sort this with the Unix command sort. user1:12345678:3.5:2.5:8:1:2:3 user2:12345679:4.5:3.5:8:1:3:2 user3:12345687:5.5:2.5:6:1:3:2 user4:12345670:5.5:2.5:5:3:2:1 user5:12345671:2.5:5.5:7:2:3:1 I need to get this: user3:12345687:5.5:2.5:6:1:3:2... (7 Replies)
Discussion started by: daniel.gbaena
7 Replies

10. Shell Programming and Scripting

Script not working..."sort" not working properly....

Hello all, I have a file - 12.txt cat 12.txt =============================================== Number of executions = 2 Total execution time (sec.ms) = 0.009883 Number of executions = 8 Total execution time (sec.ms) = 0.001270 Number of... (23 Replies)
Discussion started by: Rahulpict
23 Replies
Login or Register to Ask a Question