row count of all files with more than 0 byte


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers row count of all files with more than 0 byte
# 1  
Old 04-29-2008
row count of all files with more than 0 byte

Hi,

Is there any way to get count number of lines in all files which have more than o bytes in current directory


for example :

in /user/sri/ there are 3 files

abc 0 bytes
def 5 bytes
ghi 10 bytes

i need to get wc -l for all files which have > 0 bytes at a time ..is it possible?
# 2  
Old 04-29-2008
Sri
Since you want to count the number of lines, how does it matter if a file has 0 bytes? You could simply do "cat * | wc -l" to get the line count.

Amit
# 3  
Old 04-29-2008
amit,

My question i how to get all the counts for all files at a time in current directory..If i have 100 files which have greater than 0 byte i need to get count of all files at a time...in that particular directory
# 4  
Old 04-29-2008
Not sure I understand, can you provide an example of the desired output?
# 5  
Old 04-29-2008
Code:
find /dir -size +0 -type f | wc -l

man find.

Last edited by rubin; 04-29-2008 at 12:12 PM.. Reason: added type f
# 6  
Old 04-29-2008
Rubin,

Thanks for command..But this command displaying number of files in current directory with more than 0 bytes...but i also need number of lines in each individual file which have more than 0 bytes...lets suppose your command gives me 34 files which have more than 0 bytes in current directory..i need in each of 34 files how many lines are there like file a contains 10 lines file b contains 30 lines...like that....Is it possible? let me know...if you are still unclear?
# 7  
Old 04-29-2008
Code:
find /dir -size +0 -type f | xargs wc -l

Or sorted:

Code:
find /dir -size +0 -type f | xargs wc -l | sort           # or sort -rn

For a fancier output you can use awk in the counting statement.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split files based on row delimiter count

I have a huge file (around 4-5 GB containing 20 million rows) which has text like: <EOFD>11<EOFD>22<EORD>2<EOFD>2222<EOFD>3333<EORD>3<EOFD>44<EOFD>55<EORD>66<EOFD>888<EOFD>9999<EORD> Actually above is an extracted file from a Sql Server with each field delimited by <EOFD> and each row ends... (8 Replies)
Discussion started by: amvip
8 Replies

2. Shell Programming and Scripting

Error files count while coping files from source to destination locaton as well count success full

hi All, Any one answer my requirement. I have source location src_dir="/home/oracle/arun/IRMS-CM" My Target location dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct" my source text files check with below example.text file content $fn "\t" $dc "\t" $pc "\t" ... (3 Replies)
Discussion started by: sravanreddy
3 Replies

3. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

4. UNIX for Advanced & Expert Users

row count

Hi, I want a row count of a file incliding header and trailer If I do cat Filename | wc -l then I am only getting the row count excluding the header and trailer Buit I want the row count including Header and trailer Please help Many thanks in advance, Pragyan (3 Replies)
Discussion started by: prarat
3 Replies

5. Shell Programming and Scripting

Count the delimeter from a file and delete the row if delimeter count doesnt match.

I have a file containing about 5 million rows, in the file there are some records which has extra delimiter at random position. (we dont know the positions), now we have to Count the delimeter from each row and if the count of delimeter is not matching then I want to delete those rows from the... (5 Replies)
Discussion started by: Akumar1
5 Replies

6. Shell Programming and Scripting

count identical strings print last row and count

I have a sorted file like: Apple 3 Apple 5 Apple 8 Banana 2 Banana 3 Grape 31 Orange 7 Orange 13 I'd like to search $1 and if $1 is not the same as $1 in the previous row print that row and print the number of times $1 was found. so the output would look like: Apple 8 3 Banana... (2 Replies)
Discussion started by: dcfargo
2 Replies

7. UNIX for Dummies Questions & Answers

Script to get Row Count of ZIP Files

Hi, I have some data files in a zipped format.(eg: aa.gz).I would like to know the number or rows in each zip file(May be populate the file name and line numbers into a text file).I know the commands wc -l and gunzip,.But how I will create a shell script for this to extract each files and get... (5 Replies)
Discussion started by: abhilash_menon
5 Replies

8. Shell Programming and Scripting

row count of 60 files in one file

hi all plz some unix guy help me in this i have 60 files which will have some records i want to find the total number of records in all the 60 files like file1 has 60 and file2 has 70 record i want to sum all these and find total row count in 60 files (5 Replies)
Discussion started by: er_zeeshan05
5 Replies

9. Shell Programming and Scripting

Check if 2 files are identical byte-to-byte?

In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server. For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match. Please... (4 Replies)
Discussion started by: krishmaths
4 Replies

10. Shell Programming and Scripting

byte count and cut command

1. Is there a way to count the number of bytes of a variable? example: abc@yahoo.com is 13 bytes 2. Cut command only allows one byte for delimiter example: cut -f1 -d'.' delimited by period. Is there a way to have two or more characters in the delimiter field? thanks in adavance. :) (4 Replies)
Discussion started by: hemangjani
4 Replies
Login or Register to Ask a Question