Results 1 to 3 of 3
i'm new in linux so pls,have mercy ....:
I have to display from the list of files given as parameters the name of the
file with the largest number of ...
- 03-12-2011 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 1
awk help
i'm new in linux so pls,have mercy ....:
I have to display from the list of files given as parameters the name of the
file with the largest number of words and their number.(with AWK)
pls help me :-s
- 03-15-2011 #2
You don't need awk if you just want to count the number of words in some files. you can use wc -l. for example:
I would probably avoid awk if you are a brand new linux user unless you specifically want to use it for some reason.Code:wc -l *.txt 500 hist.txt 49612 itinerary.txt 0 testfile.txt 50112 totalRegistered Linux user #389109
My Semi-Linux Blog
- 03-16-2011 #3Linux Newbie
- Join Date
- Apr 2010
- Location
- Novosibirsk, Russia
- Posts
- 136
It seems he needs to use awk to capture wc's output, like
to get a size of 'file.txt' in variable $SZ. So you would need some kind of a loop in a script, that iterates over file names in current directory and checks its sizes. So here is an example:Code:SZ=`wc -l file.txt | awk '{ print $1; }'`
Anyway, it looks like a homeworkCode:FILES=`ls .` BIGGEST_SZ=0 for NAME in $FILES do SZ=`wc -l $NAME | awk '{ print $1; }'` if [ $SZ -gt $BIGGEST_SZ ]; then BIGGEST_SZ=$SZ BIGGEST_NAME=$NAME fi done echo "$BIGGEST_NAME has the biggest size: $BIGGEST_SZ"


Reply With Quote