![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| count number of files in a directory | finalight | Shell Programming and Scripting | 3 | 05-21-2008 09:14 PM |
| trying to count lines in multiple files | llsmr777 | UNIX for Dummies Questions & Answers | 1 | 01-23-2008 10:52 AM |
| Count the number of files in a directory | Raynon | Shell Programming and Scripting | 14 | 08-16-2007 07:07 PM |
| awk command to find the count of files ina directory | sish78 | Shell Programming and Scripting | 11 | 07-19-2007 05:00 AM |
| How to find the count of files in a directory | sish78 | UNIX for Dummies Questions & Answers | 5 | 02-01-2007 12:58 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Count files lines in a directory?
Hy!
I have some problem. Problem is that i don't now how to solve problem of average lines of files in a directory. I have managed to get number of files in a directory, but i don't know the command to count average lines of these files. I have one "for" loop that goes true whole directory... Thanks in advance! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
look into 'man wc'
|
|
#3
|
||||
|
||||
|
Use wc command to get the number of lines (if I remember correctly, wc adds one or subtracts one from the actual count). Add the total number, divided by number of files for the average number of lines.
|
|
#4
|
|||
|
|||
|
Yes but i don't know how to use wc command in a for loop on all files. I tried butt i have not managed to make it.
Example: I have 5 files in a directory. And i want to count their average lines. @RTM - your idea is good but i'm newbie in linux. I will be very gratefoul if you guys can explain a little bit more. |
|
#5
|
||||
|
||||
|
to count all '.txt' files:
Code:
#!/bin/ksh
typeset -i sum=0
typeset -i cnt=0
for i in *.txt
do
sum=$(( sum + $(wc -l < "${i}") ))
cnt=$(( cnt + 1 ))
done
printf "sum->[%d] cnt->[%d] avgSZ->[%.2f]\n" ${sum} ${cnt} "$(echo "scale=2; $sum / $cnt" | bc)"
|
|
#6
|
|||
|
|||
|
Code:
ruby -e 'c=ARGV.size;p ARGF.to_a.size/c.to_f' * |
|
#7
|
|||
|
|||
|
Yes but i need that code in linux shell script. I'm only beginning shell scripting i don't now much about it...Thanx
|
|||
| Google The UNIX and Linux Forums |