Unix Help please...
Discussion
to get a particulat column, say column 3 from a command pipe into ...
"some command" |awk '{print $3}'
du command is quite useful for finding sizes ...
eg. du -ak, see man pages for diff. options.
or ...
find /var -size +10000
where 10000 is the no of 512K blocks it will find files equal or bigger ... just change the 10000 to whatever ...
M
"some command" |awk '{print $3}'
du command is quite useful for finding sizes ...
eg. du -ak, see man pages for diff. options.
or ...
find /var -size +10000
where 10000 is the no of 512K blocks it will find files equal or bigger ... just change the 10000 to whatever ...
M
toobin said:
find $HOME -name '*.cc'| sort -nr |
this works but it shows all my .cc files
I have tried
pipe head <1>
and pipe echo $1
but neither are any good
this works but it shows all my .cc files
I have tried
pipe head <1>
and pipe echo $1
but neither are any good
Edited by toobin on Sunday 5th November 16:32
Assume they're correctly sorted biggest first. Next step select the first one e.g.
| head -1
Once you have that, select the column you want e.g. | awk '{print $3;}'
GreenV8S said:
toobin said:
find $HOME -name '*.cc'| sort -nr |
this works but it shows all my .cc files
I have tried
pipe head <1>
and pipe echo $1
but neither are any good
this works but it shows all my .cc files
I have tried
pipe head <1>
and pipe echo $1
but neither are any good
Edited by toobin on Sunday 5th November 16:32
Assume they're correctly sorted biggest first. Next step select the first one e.g.
| head -1
Once you have that, select the column you want e.g. | awk '{print $3;}'
"sort" will do all that for you;
ls -l *.cc | sort -k 5
produces a list of the cc files in size order.
ls -l *.cc | sort -r -k 5
A reverse list.
ls -l *.cc | sort -r -k 5 | head -1
The biggest file
And finally, the name of the largest cc file;
ls -l | sort -r -k 5 | head -1 | awk '{print $9}'
Next.
zumbruk said:
Next.
Thanks Zumbruk,
But I want this to run from a c shell and I still get errors.
So far what I have looks a little like this
# searches home dir for .cc files
# uses that list (xargs) and to word count and sort it
# prints the first in the list and its size
#!/bin/csh
find $HOME -name "*.cc" | xargs wc-c | sort -nr | head -1 | awk '{print $9}'
Any ideas why it returns a black line?
toobin said:
zumbruk said:
Next.
Thanks Zumbruk,
But I want this to run from a c shell and I still get errors.
So far what I have looks a little like this
# searches home dir for .cc files
# uses that list (xargs) and to word count and sort it
# prints the first in the list and its size
#!/bin/csh
find $HOME -name "*.cc" | xargs wc-c | sort -nr | head -1 | awk '{print $9}'
Any ideas why it returns a black line?
Well, firstly the "#!" needs to be the very first line in the script, else it won't work.
From your first post; "I need to create a UNIX command to find the largets c++ file in all my directories then display the largets .cc file "
I already gave you the tools to do this - all you need to do is a find . -name "*.cc" instead of the "ls", for example, this line gives you the name of the largest C file (I don't have any cc files) in the current directory and all below it;
find . -name "*.c" -exec ls -l {} ; | sort -r -k 5 | head -1 | awk '{print $9}'find . -name "*.c" -exec ls -l {} ; | sort -r -k 5 | head -1 | awk '{print $9}'
And lo, here it is;
./prog/xearth-0.92/mapdata.c
So, if you want to know how many lines the largest cc file you have is, you can do this;
wc -l `find . -name "*.cc" -exec ls -l {} ; | sort -r -k 5 | head -1 | awk '{print $9}'`
(NOTE the backticks!)
Or, did you want to know which CC file has the largest number of lines..?
find . -name "*.cc" -exec wc -l {} ; | sort -r -k 1 | head -1
huge{~}: find . -name "*.c" -exec wc -l {} ; | sort -r -k 1 | head -1
19645 ./prog/xearth-0.92/mapdata.c
And it's our old friend mapdata.c again.
I'll leave you to play with xargs to speed it up.
Regards, Z
toobin said:
Thanks Zumbruk, your assistance is greatly appreciated. 6 weeks into this MSc and a long time without sleep
ps I only commented above the #!/bin/csh to give you an idea of my logic.
I know I cannot spell largest very well but that'll be the lack of sleep
ps I only commented above the #!/bin/csh to give you an idea of my logic.
I know I cannot spell largest very well but that'll be the lack of sleep

Coo, an MSc. I'm a biochemist, me. Or rather, I was.
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff


