Results 1 to 2 of 2
Hello.
I've given a task to 'print all the files in a directory in the format---<File name> <Size in Byte> <No of Disk blocks used> ,sorted by 'disk blocks used'(reverse ...
- 08-05-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 1
Help in sorting
Hello.
I've given a task to 'print all the files in a directory in the format---<File name> <Size in Byte> <No of Disk blocks used> ,sorted by 'disk blocks used'(reverse order)..............if same no of disk blocks are used by two files then largest file will be printed first'
I used the stat command like this-
stat * -c "%n %s %b" | sort -n -r -k 2,3
but if there is a whitespace in the filename then the sorting becomes all messed up, .......if there is any way to interchange columns or anything else.
thanks for any help
- 08-05-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Hi,
One solution:
1. Print the stat output with a "|"as seperator
2. Change the default seperator of sort with the -t option to "|"
3. Replace all "|" with spaces
Try it first, if you have questions about it, feel free to ask!
Regards


Reply With Quote