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
162
votes
13 answers

How can I search for a multiline pattern in a file?

I needed to find all the files that contained a specific string pattern. The first solution that comes to mind is using find piped with xargs grep: find . -iname '*.py' | xargs grep -e 'YOUR_PATTERN' But if I need to find patterns that spans on…
Oli
  • 15,345
  • 8
  • 30
  • 36
13
votes
3 answers

How to check if one file is part of other?

I need to check if one file is inside another file by bash script. For a given multiline pattern and input file. Return value: I want to receive status (how in grep command) 0 if any matches were found, 1 if no matches were…
abrzozowski
  • 389
  • 1
  • 3
  • 12
8
votes
1 answer

How to install / enable pcregrep on Cygwin?

I'm trying to use pcregrep as specified in the top answer to this SO question on Cygwin. My environment is Win7 64bit running Cygwin V 1.7.20(0.266/5/3). Using cygcheck -p pcregrep I get: Found 6 matches for pcregrep libpcre-devel-8.37-1 -…
delliottg
  • 3,950
  • 3
  • 38
  • 52
3
votes
1 answer

pcregrep: how to match only the first occurence?

I have a lot of files in the following format: SIMPLE { residualControl { p 1e-4; U 1e-4; "(k|omega|epsilon)" 1e-4; } nNonOrthogonalCorrectors 0; pRefCell 0; …
s.ouchene
  • 1,682
  • 13
  • 31
3
votes
1 answer

How to highlight text by using regex

I'm trying writing a script to help highlight when match with regex. Below is my example that what I do now. var text = "SOMETHING ~WEIRDs~ AND Not WEIRD"; var regexp = /\b(WEIRD)\b/ var matches = text.match(regexp); for (i = 0; i <…
Deno
  • 434
  • 4
  • 16
3
votes
5 answers

Manipulate txt searching for three pattern (sed,awk,pcregrep)

i have got this text file AAAA 1234 title example Lorem Ipsum FF AAAA 1234 title example €330 - Roma FF I want to extract from this file only the txt that: START WITH AAAA HAS Euro SYmbol END WITH FF In this case i want to match only that…
Francesco
  • 41
  • 7
3
votes
1 answer

Using pcregrep -M to search for a multi-line string

I am trying to use pcregrep -M to search for a multiline string. This is the line in my script: lineNumber=$(pcregrep -Mn '$firstLine.*\n.*$secondLine.*' $myFile) myFile contains multiple lines of the form: firstLine\n secondLine(with other…
CLK
  • 211
  • 3
  • 7
2
votes
3 answers

translate pcregrep into Perl one-liner

I need to find all active network interfaces on new macOS. That means the following one-liner with pcregrep will not work: ifconfig | pcregrep -M -o '^[^\t:]+(?=:([^\n]|\n\t)*status: active)' because pcregrep is no default install on macOS. I tried…
2
votes
2 answers

grep to find literal [square brackets] with specific data

My file contains the following lines: hello_400 [200] world_678 [201] this [301] is [302] your [200] friendly_103 [404] utility [200] grep [200] I'm only looking for lines that ends with [200]. I did try escaping the square brackets with the…
Kavish Gour
  • 183
  • 8
2
votes
1 answer

PCRE regex behaves differently when moved to subroutine

Using PCRE v8.42, I am trying to abstract a regex into a named subroutine, but when it's in a subroutine, it seems to behave differently. This outputs 10/: echo '10/' | pcregrep '(?:0?[1-9]|1[0-2])\/' This outputs nothing: echo '10/' | pcregrep…
2
votes
3 answers

Using pcregrep to grep multiple lines

I have a file with the following pattern. Foo $var1 ......... ......... Foo $var2 .......... .......... .......... Yes I would only like to match the "section" which starts with "Foo" and has "Yes". (You will notice there is an empty line feed at…
dochenaj
  • 33
  • 6
2
votes
1 answer

Why does this multi-line regular expression include the following line?

I have the following input and I'd like to write a regular expression which would match every line except the first and last. 2019-03-13 00:33:44,846 [INFO] -: foo 2019-03-13 00:33:45,096 [INFO] -: Exception sending email To: [foo@bar.com,…
Michael
  • 41,989
  • 11
  • 82
  • 128
2
votes
1 answer

How to show only first match in pcregrep?

I have xml in log-files, that looks like: 1 text text text 2 text So, i need to cut this XML from log file and i'm trying to do this with: pcregrep -M '(\n|.)*' But after…
newSqlz
  • 133
  • 8
2
votes
2 answers

PCRE regex whitespace

I am trying to write a regex to pull all non-comment and non-empty lines from /etc/samba/smb.conf. Comments are lines that: start with # start with ; start with any amount of whitespace followed immediately by either # or ; I tried the…
nhavens
  • 252
  • 1
  • 3
  • 11
2
votes
3 answers

Python multi-line pattern matching

I am trying to match a multiline pattern using a shell command through python. I am able to match using the shell commands but I am not able to pass this command through the Python subprocess.call or the os.system modules. My file looks something…
sanjay
  • 647
  • 1
  • 6
  • 14
1
2 3 4 5 6