Counting rows in many files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Counting rows in many files
# 1  
Old 09-02-2008
Counting rows in many files

I'm regularly counting the number of rows in a number of files. I need to know how many rows their are in all files together. Counting rows in one file I can handle, but how do I count rows in all at once?

I'd be grateful for any answer.
# 2  
Old 09-02-2008
assuming your current working directory is where the files live:
Code:
wc -l * | tail -1

# 3  
Old 09-02-2008
Quote:
Originally Posted by jim mcnamara
assuming your current working directory is where the files live:
Code:
wc -l * | tail -1

thanks... but that would count all files in the folder wouldn't it? Maybe I was a bit unclear.

is there some way to specify which files, like WOWEBADMCHANGESBOSS*

Which would only count the files starting with this.
# 4  
Old 09-02-2008
Put WOBASMANBLOB* (or whatever) where I have just the single * character
# 5  
Old 09-02-2008
Quote:
Originally Posted by jim mcnamara
Put WOBASMANBLOB* (or whatever) where I have just the single * character
You're a star... thanks
# 6  
Old 09-02-2008
Quote:
Originally Posted by jim mcnamara
Put WOBASMANBLOB* (or whatever) where I have just the single * character

The number of arguments that can be replaced by * will be limited in most of the unix flavours..This case will arise if there are many files

One approch is:

Code:
find . -name "WOBASMANBLOB*" -type f -exec wc -l {} \; | awk '{ sum+=$1 }END{ print sum }'

# 7  
Old 09-02-2008
Quote:
Originally Posted by dennis.jacob
The number of arguments that can be replaced by * will be limited in most of the unix flavours..This case will arise if there are many files

One approch is:

Code:
find . -name "WOBASMANBLOB*" -type f -exec wc -l {} \; | awk '{ sum+=$1 }END{ print sum }'

you don't need two commands here

Code:
awk '{ linecnt++ }END{ print linecnt }' WOBASMANBLOB*

I guess it boils down to the same problem again

Last edited by matrixmadhan; 09-02-2008 at 09:29 AM.. Reason: wrong command
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Counting and rearranging the rows

Hi, I have a file that I re-arranged using awk and unix commands to produce a file that looks like this: JOE JOE JOE JOE JOE BOB BOB HI HI HI I want to count how many of the same rows there are and print it on the second column while only maintaining the original name once. The... (5 Replies)
Discussion started by: phil_heath
5 Replies

2. UNIX for Dummies Questions & Answers

Counting files without ls or wc

i need to write a shell script to "count the number of files in the current directory but without using either ls or wc command"..... please help! (1 Reply)
Discussion started by: lexicon
1 Replies

3. Shell Programming and Scripting

Counting rows line by line from a specific column using Awk

Dear UNIX community, I would like to to count characters from a specific row and have them displayed line-by-line. I have a file called testAwk2.csv which contain the following data: rabbit penguin goat giraffe emu ostrich I would like to count in the middle row individually... (4 Replies)
Discussion started by: vnayak
4 Replies

4. Shell Programming and Scripting

Counting Files

In a script, how would I go about finding the number of files for the first parameter after my script name? For instance, my script name is myscript.sh and the folder I am checking is not the current working directory, lets say it's folder1. so I type myscript.sh folder1 This script below... (2 Replies)
Discussion started by: Confirmed104
2 Replies

5. Shell Programming and Scripting

multiple files: counting

In a directory, I have 5000 multiple files that contains around 4000 rows with 10 columns in each file containing a unique string 'AT' located at 4th column. OM 3328 O BT 268 5.800 7.500 4.700 0.000 1.400 OM 3329 O BT 723 8.500 8.900... (7 Replies)
Discussion started by: asanjuan
7 Replies

6. Shell Programming and Scripting

Deleting specific rows in large files having rows greater than 100000

Hi Guys, I need help in modifying a large text file containing more than 1-2 lakh rows of data using unix commands. I am quite new to the unix language the text file contains data in a pipe delimited format sdfsdfs sdfsdfsd START_ROW sdfsd|sdfsdfsd|sdfsdfasdf|sdfsadf|sdfasdf... (9 Replies)
Discussion started by: manish2009
9 Replies

7. Solaris

Counting up files

Hi, I have a load of if statements that look for files in a directory, I want to be able to count them up and the total files confirmed in an email? I ahve tried expr but i this does not work and it only reads in the first if and ignores the rest. Please see script, #!/bin/ksh ... (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

8. Shell Programming and Scripting

Help with counting files please

Hi all. If I have a unix directory with multiple files, lets say, I have some with .dat extensions, some with .txt extensions, etc etc. How in a script would I provide a count of all the different file types (so, the different extensions, I guess) in the directory?? So if I had: test.dat... (6 Replies)
Discussion started by: gerard1
6 Replies

9. UNIX for Dummies Questions & Answers

counting files

Which one line command can count and print to the screen the number of files containing "a" or "A" in their name (5 Replies)
Discussion started by: Edy
5 Replies
Login or Register to Ask a Question