grep count across multiple files


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users grep count across multiple files
# 1  
Old 05-07-2008
grep count across multiple files

I have a number of simulation log files and I want to get a total count of the "PASSED" expression in them. If I use grep -c <files>, grep would give a tally for each file. I just want one number, the total count. How do I do that?
# 2  
Old 05-07-2008
Code:
grep -c PASSED <files> | awk -F: '{ s+=$2 } END { print s }'

# 3  
Old 05-07-2008
Hi.

You could cat them all and pipe into grep ... cheers, drl
# 4  
Old 05-14-2008
grep -l <string> <files> | wc -l
# 5  
Old 05-15-2008
That counts the number of files with PASSED in them, I was under the impression that the number of lines was the interesting number (there could be more than one per file).

Second drl's suggestion;

Code:
cat files | grep -c PASSED

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep strings on multiple files and output to multiple files

Hi All, I want to use egrep on multiple files and the results should be output to multiple files. I am using the below code in my shell script(working in Ksh shell). However with this code I am not attaining the desired results. #!/bin/ksh ( a="/path/file1" b="path/file2" for file in... (4 Replies)
Discussion started by: am24
4 Replies

2. Shell Programming and Scripting

Count Unique values from multiple lists of files

Looking for a little help here. I have 1000's of text files within a multiple folders. YYYY/ /MM /1000's Files Eg. 2014/01/1000 files 2014/02/1237 files 2014/03/1400 files There are folders for each year and each month, and within each monthly folder there are... (4 Replies)
Discussion started by: whegra
4 Replies

3. Shell Programming and Scripting

Count files between multiple directories

Hi All, Everyday we will receive 33 files in our source directory(/prd/pk) with the current date. Once our jobs are completed all the 33 files immediately will be moved to backup folder (/prd/pk/backup). Now, I need to check between source file directory (/prd/pdk) and backup file directory... (3 Replies)
Discussion started by: suresh_target
3 Replies

4. Shell Programming and Scripting

Count the number of occurances for multiple files

I have some text files as shown below. I would like to add the values of each string. Your help would be appreciated!! file1.txt SUS 2 PRS 2 ALI 1 PRS 1 GLK 2 file2.txt PRS 3 GLK 6 SUS 18 Desired output SUS 20 PRS 6 (2 Replies)
Discussion started by: arch
2 Replies

5. Shell Programming and Scripting

Count lines from multiple files (3)

Hey everyone, I've to count lines from string of files names then to show sum output of lines. for example: read x = F1 F2 F3 F1 = 12 lines F2 = 14 lines F3 = 10 lines = 36 what I did is: read x echo $x >|temp for x in $(cat temp) do wc -l < $x (3 Replies)
Discussion started by: Aviv
3 Replies

6. Shell Programming and Scripting

count characters in multiple files and sort

I am trying to count a special character in several thousand files and sort the result according to the number the character occured in each files. files: 1.txt 2.txt 3.txt files look like: ABCDEFGHABBBACF I want the number of B in each file and a result file that lists the occurence... (4 Replies)
Discussion started by: patdoor
4 Replies

7. UNIX for Dummies Questions & Answers

Grep multiple strings in multiple files using single command

Hi, I will use below command for grep single string ("osuser" is search string) ex: find . -type f | xarg grep -il osuser but i have one more string "v$session" here i want to grep in which file these two strings are present. any help is appreciated, Thanks in advance. Gagan (2 Replies)
Discussion started by: gagan4599
2 Replies

8. Shell Programming and Scripting

Count occurance of multiple strings using grep command

How to grep multiple string occurance in input file using single grep command? I have below input file with many IDP, RRBE messages. Out put should have count of each messages. I have used below command but it is not working grep -cH "(sent IDP Request)(Recv RRBCSM)" *.txt ... (5 Replies)
Discussion started by: sushmab82
5 Replies

9. UNIX for Dummies Questions & Answers

trying to count lines in multiple files

Hi there, I need help. I want to run the command: less filename | wc -l But on multiple files in a directory So to get those files I would run ls -ltr | grep filename_2000123 or of course ls -ltr *filename_2000123* But I am having a problem running a loop to get a count of each... (1 Reply)
Discussion started by: llsmr777
1 Replies

10. Shell Programming and Scripting

Grep, count and match two files

I am writing the below script to do a grep and count number of occurances between two tab delimited files. I am trying to achieve.. 1) Extract column 2 and column 3 from the S.txt file. Put it in a temp pattern file 2) Grep and count column 2 in D.txt file 3) Compare the counts between... (19 Replies)
Discussion started by: madhunk
19 Replies
Login or Register to Ask a Question