ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm writing a script to take a list of directories in a file(formatted: dir,spaceused) and echo the 5 largest to the screen. I can't figure out the math operation/loop to handle this. Any help?
Thanks but that wouldn't work for my need. I've got a listing in a file(looking back it's not important that it's directories) that is created by another script. Not exactly what I'm looking for but it's got me thinking.
I could use a sed to remove the directory names that are in the file created by the original script, sort what is left which would be the size on disk and then grep for the largest file sizes but, unless I'm overthinking or don't know a way to pull it off, this would only print the largest 5 times and probably take a bit to run...
thanks for the replys, that sort command doesn't seem to be working. not sure what I should be putting after the -k, man page isn't helping much. I thought it should be the character where I want the sort to start but that's not what it's doing. I do need the directory names printed as well.
I think it depends on the separator. Sort probably takes white-spaces by default as the separator between columns. I think theres some switch for it. To skip a field, +m. (+1 skips one field).
So `cat InFile | sort +1nr`
sorts on the second field, by byte count (numeric) and reversed.
k, that won't work then, there is no whitespace in the other file. Settled on the sed/sort/tail command and then doing a loop back through the original. not to difficult but I can't think apparently, I'm not getting this loop to work.
do
sed -e 's/\(.*,\)\(.*\)/\2/' $1.dir | sort -n | tail -n 5 >> tempd.out
for dir in `cat tempd.out`
echo "`grep $dir $1.dir`"
done >> outfile
that's the code as it is now. I need two loops as there are two files that the sed/sort/tail/cat/grep needs to run through. As I've been doing it, I either end up with it not doing anything, endless loop, or unexpected do/done/echo.
K, trying to finish this up. Now need to organize the data a specific way. I had it just do two seperate "charts" but that's apparently not good enough. I had it do:
User Disk Usage
-------------------------
Directory Disk Usage
-----------------------------
but what is wanted is:
User User Disk Usage Directory Directory Disk Usage
------------------------------------------------------------------------------
the data gets pulled from one file in the format:
user,19023745
user2,429375
user3,398157
user4,193265
user5,6572
dir1,10594601982
dir2,63195987
dir3,56818763
dir4,315617
dir5,156399
any help getting it in the format wanted would be greatly appreciated.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.