shellscript help

romeozor

Limp Gawd
Joined
Jun 2, 2006
Messages
223
greetingz,

first of all yes this would be homework, and YES i DID read the rules about it, but i'm only asking for help not a solution.

so the deal is: make a script which finds the 4 files which have the most words in it in the current dir and subdirs

so here's what i have come up with so far:
Code:
find . -exec wc -w '{}' \;

so this scans fine and outputs the words in the files, but i have no clue how to go on. i was thinking if i could sort it somehow then i could use the head/tail commands to cut the info i would need
i also thought outputting the text to some file then make a scan on it or something but that would seem complicated

so am i allowed to get help? ^^

edit:
seems i solved my problem
Code:
find . -exec wc -w '{}' \;| sort -g
so this gets it sorted and
Code:
find . -exec wc -w '{}' \;| sort -g | tail -n4
gives me the 4 files with the most words in it

but this also gives some "wc: ./somethig is a dir" and this just makes it ugly, any thoughts of getting rid of it?
 
Look for -type in the man page for find.
(You search manpages by pressing / , btw. Press n for the next match.)
 
For future reference check out -mindepth and -maxdepth. Your professor may ask you to look in directories only n deep or no more than n deep.
 
HHunt said:
Look for -type in the man page for find.
(You search manpages by pressing / , btw. Press n for the next match.)

thx a bunch m8, found the "-type f", looks great :)
 
Back
Top