|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
count words and empty files
Hello,
I will count words in a file (or more files) and count (if given up) empty files (test -z?), how can I do this? Like this: There are "108" words in "3" files There are "2" empty files Thanks for your reaction. Regards, Arjan Engbers (My English is not good, I hope you understand me) |
| Sponsored Links | ||
|
|
|
#2
|
|||
|
|||
|
Hi, arjanengbers: To count the number of words in each file in the current directory (including empty files): Code:
wc -w * Regards, Alister |
|
#3
|
||||
|
||||
|
Code:
find ~ -empty -type f | wc -l Use the above command for finding the empty files count in the home directory(~) You can use some specific path for finding the empty files under that path. |
|
#4
|
||||
|
||||
|
Code:
for i in $@
do
if [ ! -s $i ]
then
echo "$i is empty";
fi
echo `wc -w $i`;
doneLast edited by murugaperumal; 03-14-2010 at 11:52 PM.. |
|
#5
|
||||
|
||||
|
Solution
try the following ,it will give you the exact output, Code:
j=0
k=0
count=0
total=0
for i in $@
do
if [ -s $i ]
then
count=`wc -w $i|cut -d ' ' -f 1`
let total=$count+$total
let k=$k+1
else
let j=$j+1
fi
done
echo "There are \"$total\" words in $k files"
echo "There are \"$j\" empty files"
|
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| perl: count columns/words in a string | hcclnoodles | Shell Programming and Scripting | 2 | 02-18-2010 09:28 AM |
| Count the no of lines between two words | zsudarshan | Shell Programming and Scripting | 5 | 09-17-2009 10:01 AM |
| count no of words in a line | Satyak | Shell Programming and Scripting | 3 | 09-26-2008 11:52 AM |
| Count of Field for Non-Empty | Swapna173 | UNIX for Dummies Questions & Answers | 2 | 08-08-2008 09:48 AM |
| count no of words in a line | satish@123 | Shell Programming and Scripting | 7 | 05-21-2008 02:59 AM |