Questions tagged [pcregrep]

pcregrep searches files for character patterns, in the same way as other grep commands do, but it uses the PCRE regular expression library to support patterns that are compatible with the regular expressions of Perl 5.

76 questions
1
vote
0 answers

How to optimize a regex with PCREGrep to avoid hitting resource limits

I'm trying to grep for suppressions containing a certain library in a Valgrind log which is a couple of million lines long with PCREGrep. I can get each suppression individually using pcregrep -M "{\n([^}]+\n)+}" which produces individual entries…
Emily-TTG
  • 531
  • 3
  • 18
1
vote
2 answers

Multiline RegEx to match YAML Frontmatter, only the first match, only when preceded by nothing other than space

Problem The problem description is simple; I have a pile of text files, from which I wish to extract the frontmatter (described anon) alone, if it's there are all, and then stop processing the file any further. Here's a sample valid example of a…
khosrow
  • 8,799
  • 4
  • 21
  • 24
1
vote
5 answers

How do I count multi line recurring pattern in a file?

I have a file that has the following pattern. A . . XYZ . . A . . A . . A . . XYZ where "."s are new lines with random words (not A or XYZ). I want to count all the occurrences of patterns that match A . (any number of lines) XYZ I also want to…
Pranav
  • 11
  • 2
1
vote
1 answer

Creating a bash script to match multiline patterns in log files

I'm trying to automate some time consuming tasks/log checking, building a system that I will replicate to other uses. I have a logfile for example: ...multiline ACTION Text where all is good... ERR-101 Something is wrong ERR-201 Something is wrong…
WhenYouDev
  • 11
  • 3
1
vote
1 answer

Is possible to discard outer brackets in regex and consider inner bracket inside?

I have many patterns with bracket enclosure, I made a regular expression where is not considering brackets and just only what is inside/between them, but exists a problem when the text within brackets contain [] brackets too. Thanks! Regex:…
dcubaz
  • 11
  • 2
1
vote
1 answer

Regex for multiline patterns then they are following each other

I'm trying to find lines that have "aaa" and "bbb" in that order, and those strings are on different lines. 11 aaa blah blah bbb blah blah blah blah blah blah aaa blah blah blah blah blah blah blah blah 11 bbb blah blah blah blah blah blah With…
Alex
  • 350
  • 5
  • 20
1
vote
1 answer

first occurance for pattern across multiple lines using pcregrep

Referring to question below, it seems that pcregrep does not narrow the result to the first occurance but expands to the maximum extent possible. So if for e.g. the content is: blah blah.. blah blah.. blah abc blah blah blah.. blah blah.. blah…
1
vote
1 answer

How pcregrep force to return first match of regexp

I have ci-pipelines and there are a lot of before_scripts sections. I would like to make a multiline regexp. I export all before script to my-ci-jobs.txt with python script. pcregrep -M 'before_script.*\n.*' my-ci-jobs.txt "before_script": [ …
dorinand
  • 1,397
  • 1
  • 24
  • 49
1
vote
2 answers

pcregrep or grep: searching with lookaheads not working

I am trying to search for a regex with lookahead its not working in pcregrep or grep I want to search for bits of sections which may span over multiple lines, which start with PQXY at the beginning of a line and end with OFEJ at the end of the…
Santhosh
  • 9,965
  • 20
  • 103
  • 243
1
vote
1 answer

match a floating point number that is not inside parenthesis

I'm trying to match a pattern in a bunch of files with grep. The files contain G-code (CNC machine code). Every number should have a letter associated with it (example: X4.5, G71, Z-0.75). Many files have typos and are missing the letters. I'm…
1
vote
1 answer

How do I match the last occurrence of Pattern before another Pattern with REGEX

I have a huge XML file and I need to extract the content of a whole tag that contains a sequence of numbers. Everything is one line in my file, I added line breaks here to make it more readable So here I have a simplified example The…
1
vote
1 answer

shell - How to match content between xml tags?

I have this file: 1 0 40001
Joe
  • 791
  • 1
  • 9
  • 24
1
vote
1 answer

Extract multiple lines only if all patterns matches on the same order

I am encountering the similar difficult that was asked here. My Linux log file (sample log file) contains entries as below and I’d like to grep the lines ‘Total Action Failed :’ and ‘Total Action Processed:’ only if these two lines are followed by…
PraveenKS
  • 1,145
  • 3
  • 13
  • 28
1
vote
1 answer

Why is this Regex not capturing both matching lines?

I have the following text file: a a I am trying to match lines that start with a using the following command: pcregrep -M '^a'. It is matching only the first a and not the second. Does anyone know why? I am using pcregrep because this is a simple…
gkeenley
  • 6,088
  • 8
  • 54
  • 129
1
vote
2 answers

Why is the positive lookahead in my pcregrep Regex not working?

I wrote a Regex using pcregrep, and everything behaved as expected until I added a positive lookahead. Scenario: I have the following text file: a b c a c Goal: I want to use a Regex with pcregrep to return a line containing a and a line containing…
gkeenley
  • 6,088
  • 8
  • 54
  • 129