Find the answer to your Linux question:
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 ...
  1. #1
    Just Joined!
    Join Date
    Aug 2007
    Posts
    1

    Post 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

  2. #2
    Linux 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...