Tags down


Count number of files with certain string in it [PHP]

By : snjall
Date : September 17 2020, 03:00 AM
this will help I have a directory with subdirectories in it, I am trying to loop over all of them and also loop on the filenames to count how many time there is a string inside it. , Just add a test for the values and put a counter here:
code :
$posteCounter = 0;
foreach (glob($directory . $subDirectory . '/*') as $file) {

    $poste_explode = explode('-', $file);
    $poste = $poste_explode[1];
    if(200 == $poste || 263 == $poste) {
//set variables outside the loop to hold the values
$_200 = 0;
$_263 = 0;

if(200 == $poste) {
} elseif (263 == $poste) {
foreach(glob($directory . $subDirectory . '/*') as $file) {

    $poste_explode = explode('-', $file);
    $postes[] = $poste_explode[1]; // create and populate $postes array

$filenames = ['a-2-foo', 'b-2-bar', 'c-3-glorp'];

foreach($filenames as $filename){
    $poste_explode = explode('-', $filename);
    $postes[] = $poste_explode[1];
    if(!isset(${'poste_' . $poste_explode[1]})){
        ${'poste_' . $poste_explode[1]} = 0; // set up variable variable

var_dump( get_defined_vars() );


foreach($postes as $poste){
    echo $poste . "\n";
    foreach($filenames as $filename){
        $poste_explode = explode('-', $filename);
        if($poste == $poste_explode[1]){
            echo ${'poste_' . $poste} . "\n";
            ${'poste_' . $poste}++; // variable variable

Share : facebook icon twitter icon

How can I find and count number of files matching a given string?

By : Nimco Libaan
Date : March 29 2020, 07:55 AM
will be helpful for those in need I want to find and count all the files on my system that begin with some string, say "foo", using only one line in bash. , You can use
code :
find / -type f -name 'foo*' | wc -l

How to count the number of files starting with a specific string?

By : Vekteur
Date : March 29 2020, 07:55 AM
wish helps you NSLog the files in the resources dir that contain thing1 in their filename:
code :
NSError *error = nil;
NSArray *dirContents = [resources contentsOfDirectoryAtPath:@"resources" error:&error];
if ([dirContents count] > 0 && error == nil){
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF contains[dc] %@",@"thing1"];
    NSLog(@"%@", [dirContents filteredArrayUsingPredicate:pred]);
else if ([dirContents count] == 0 && error == nil){
    NSLog(@"Empty directory."); 
} else {
    NSLog(@"error: %@", error); 

How can I count the number of files containing a specific string but not containing another string?

By : marto642
Date : March 29 2020, 07:55 AM
I wish this helpful for you Loop over the files and perform a proper check. Searching the string will outweigh any overhead created by the shell counting.
code :
declare -i fail=0
declare -i success=0

for fileName in *
  if grep -q FAILED "$fileName"
  elif grep -q OK "$fileName"

printf "%d failed, %d succeeded\n" "$fail" "$success"
grep -l OK $(grep -L FAILED *) | wc -l
(grep -l FAILED *; egrep -L 'FAILED|OK' *) | wc -l

how to count the number of time a specific string is repeated in a set of files and get the names of the files using pyt

By : edensan
Date : March 29 2020, 07:55 AM
help you fix your problem You can do this using the grep utility.
code :
joe@linuxbox ~/Desktop/eclipse/test/src $ grep -c "student" *.txt

Bash: Count number of occurrences for a particular string from multiple log.gz files

By : BrianHwang
Date : March 29 2020, 07:55 AM
wish help you to fix your issue As a title, I got several fairly large log.gz files in my folder. The size of these log.gz files is about 4GB each. , Could you please try following and let me know if this helps you.
code :
zgrep -c 'abcdef' *.gz
Related Posts Related Posts :
  • Laravel database design multi-level categories with product details table
  • Data not stored in database
  • Why should the error_log file be private
  • Testing authorization on API Platform
  • Why i cant retrieve the date from database
  • How to generate a pdf invoice from mySQL table using FPDF for a specfic id
  • PDO SQL Delete statement not found
  • php text file to array of arrays
  • PHPWord - setting font inside Template Processor
  • Laravel URL redirecting back
  • Authentication in Laravel using 2 tables
  • Problem with DocuSign, migrating from dev environment to prod environent (Go-Live)
  • Laravel - it is looking for a column "deleted_at" even if I didn't created that column
  • how to change max_input_vars value on godaddy server
  • How to clear memory on each execution?
  • Rewriting HTML anchor using str_replace and regex
  • How to use doctrine with slim framework 4?
  • Php nothing happens when I click login, just removes both fields
  • How to Store multiple values in single field laravel
  • WordPress get last insert id from database
  • how do i go getting this eloquent relationship right?
  • Symfony two services in docker configuration
  • PHP MySQL if date and time unavailable add to alert message
  • If i load the checkboxes from database, and i uncheck the checkbox after submit it is still checked
  • Your requirements could not be resolved to an installable set of packages (phpseclib/bcmath_compat)
  • Map associative array to another array php
  • Laravel orderBy highest points
  • Unable to populate cell by zero value from $_GET array
  • PHP downloading will randomly give a network error
  • Shortcode style parsing
  • Data not Inserting In WordPress Database
  • Converting a nested if-else based on range condition into switch statement
  • Why is the use language construct in php unable to see changes in the value of a variable?
  • Laravel + Swift Mailer: Error: no valid recipients
  • Magento 2 installation on Manjaro (Arch Linux) ~ php extension missing
  • How to prevent manually set url in laravel
  • How to enable XDebug in Apache but not in CLI?
  • Redirect to the prev of the prev url
  • how to configure php email in blue host to use mail() function?
  • php variable scope - include/required scripts vs ajax
  • How to write question in Markmail support (i.e. open meeting support)
  • Laravel query not working when using as scope
  • LexikJWTAuthenticationBundle | JwtToken is working but Authentication says "Full authentication is required to acce
  • how can i use variable in where condition ( in clause) in yii2
  • Fix broken unicode escape without leading slash in PHP
  • What is called after a Data Persister on Api-Platform?
  • How can I stop the regex at first match?
  • How can I echo ( php for loop variables ) in html table?
  • Function that echo string then replace letters
  • svg programming, coords are messed up
  • Is there any array function to make array value as key and other value as value of that key?
  • Difference between get_discount_total() and get_total_discount()?
  • Ajax call using Laravel not working when ad blocker is enabled
  • How to create a function that check multiple values passed as an argument
  • Fetch current and next row and compare in a loop
  • How to Import CSV to 'Update' existing record in DB using Laravel
  • PHPMailer doesnt seem to work with Hostgator Hosting
  • Changing file permissions in php
  • index.php page not loading on main domain on a GCE VM instance
  • Prepared Statement Inside Stored Procedure Called by PHP Prepared Statement
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk