logo
down
shadow

Find last 30 occurrences of a string in a log file using Perl


Find last 30 occurrences of a string in a log file using Perl

By : user2951883
Date : November 18 2020, 03:49 PM
To fix this issue
I need to find the last 30 occurrences of a string (i.e. after every 15 minutes). After that, I need to save them in an array.
code :
use strict;
use warnings;
use 5.016;

my $fname = 'mylog.log';

open my $LOGFILE, '<', $fname
    or die "Couldn't open $fname for reading: $!";

my $text;

{
    local $/ = undef;
    $text = <$LOGFILE>;
}

my $regex = qr{
    [(]  
    \d\d
    [.]
    \d\d
    [)]
    K/s
}xms;

my @matches = ($text =~ /$regex/g);

my $n = 2;
my @last_n_matches = @matches[-$n..-1];
say for @last_n_matches;

--output:--
(22.22)K/s
(33.33)K/s


Share : facebook icon twitter icon
In a batch file, how to find the occurrences of string in a textfile?

In a batch file, how to find the occurrences of string in a textfile?


By : ching nain
Date : March 29 2020, 07:55 AM
To fix the issue you can do Maybe the findstr command will help you: Findstr Help. It doesn't print the number of occurences, but maybe you can do something with the results.
UPDATE: The Find command has a /c option, which counts the number of lines containing that string.
Find all occurrences of a string in a file

Find all occurrences of a string in a file


By : Sachithra Gayan
Date : March 29 2020, 07:55 AM
I hope this helps you . You're never actually advancing any pointer of any kind, so it has no way of knowing that it already found the first match.
Now, depending on your input, you may be able to just use a regex:
code :
preg_match_all("(".preg_quote($string1).".*?".preg_quote($string2).")s",$report,$matches);
find occurrences of a string in a large file that cannot fit memory

find occurrences of a string in a large file that cannot fit memory


By : Christian Ruiz
Date : March 29 2020, 07:55 AM
wish of those help If you use generators you can access a big file and do the processing.
simple grep command,
code :
def command(f):
    def g(filenames, **kwa):
        lines = readfiles(filenames)
        lines = (outline for line in lines for outline in f(line, **kwa))
        # lines = (line for line in lines if line is not None)
        printlines(lines)
    return g

def readfiles(filenames):
    for f in filenames:
        for line in open(f):
            yield line


def printlines(lines):
    for line in lines:
            print line.strip("\n")

@command
def grep(line, pattern):
    if pattern in line:
        yield line


if __name__ == '__main__':
    import sys
    pattern = sys.argv[1]
    filenames = sys.argv[2:]
    grep(filenames, pattern=pattern)
find string with most occurrences in .txt file with powershell

find string with most occurrences in .txt file with powershell


By : Fabio Luiz
Date : March 29 2020, 07:55 AM
This might help you I'm currently working on a school assignment in powershell and I have to display the word longer then 6 characters with the most occurences from a txt file. I tried this code but it's returning the number of occurrences for each word and it's not what i need to do. Please help. , You can do something like the following:
code :
$a = Get-Content -Path .\germinal_split.txt
$a | Where Length -gt 6 | Group-Object -NoElement | Sort-Object Count -Descending
Find all occurrences of string in html file

Find all occurrences of string in html file


By : Arvin Bhangu
Date : March 29 2020, 07:55 AM
wish help you to fix your issue you can use find_all(), like:
code :
for el in html.find_all("h3", class_="chart_row-content-title"):
    tracklist = el.get_text()
allTexts = [ele.get_text() for ele in html.select('h3.chart_row-content-title')]
Related Posts Related Posts :
  • Regex wheel size or digits after point
  • Replace number with repeated characters
  • Regex replace hexadecimal characters
  • Pasting character vectors, removing NA's and separators between NAs
  • Perl: basic perl regex parsing for word@word
  • %0 is not replaced by server name when used with Apache's ProxyPassMatch
  • Regular expression for two fields on JSON response - Jmeter
  • Adding to the requirejs optimizer fileExclusionRegExp
  • grep file with full contain string
  • merge two regular expressions in vs2010
  • Get substring up until the first question mark
  • Regular expression to match part of word
  • editing a JSON file with sed
  • R: RegEx for coordinates
  • Regex 5 digits number from Subject Line in MS Outlook
  • PERL: Matching multiple patterns
  • Extract location data using regex in R
  • Extracting Dates Using Regular Expression in R using grepl
  • Regex with multiple optional groups
  • Pseudo currency regex
  • Subject to permlink convertion in bash
  • Regular expression replace all occurrences of any word beginning with a certain substring
  • Umbraco 7 regex error: Value is invalid, it does not match the correct pattern
  • Regex using Vala and GLib
  • How to match multi-row data using regular expression R programming
  • Capitalize words in a bash variable using sed
  • How to use regex in bash for selecting a string between double quotes?
  • Golang to match dash(hyphen) character
  • How to express a escape sequence in regex. ("" -> ")
  • Regular Expression - Perl
  • Regex That Pulls Certain Bits From a String
  • Regex: This or that or none
  • Copying text from one line to another
  • find string that consists only of a certain set of characters
  • Sublime Text 3: How to change the notation from ``->cls`` to some macro?
  • VBScript Return an entire line when searching for a string
  • Unwind array of objects mongoDB
  • To delete the last character with regex
  • Understanding negative lookahead
  • How can I exclude a string if it ends in ".d.ts"?
  • Need help regarding forming a regular expression -xml
  • Using sed to replace string in file by using regex capture group
  • How to match a sequence of whitespaces with c++11 regex
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org