Reputation: 84
How can I get an array of filenames of all files in specified directory sorted by size of file. For example if I have files with next sizes:
file1 58
file2 32
file3 178
I want to get something like this:
set arr = (file2 file1 file3)
Upvotes: 1
Views: 366
Reputation: 785128
Assuming you can store output as shown in question in a file sort
and cut
can work:
sort -nk2,2 file | cut -d ' ' -f1
file2
file1
file3
and using set directly:
set arr = (sort -nk2 * | cut -d ' ' -f1)
Upvotes: 1