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.
Questions tagged [pcregrep]
36 questions
5
votes
3 answers
How to grep for repeated patterns of repeated patterns?
I have a text file, fred.txt:
% cat -e fred.txt
00:$
00:04:$
01:00:23:34$
01:$
01:40:$
01:40:32:$
%
I can grep for a line with 2 digits and a colon:
% pcregrep -e '[\d]{2}:' fred.txt
00:
00:04:
01:00:23:34
01:
01:40:
01:40:32:
%
but when I try…
Johnny Rollerfeet
- 145
- 1
- 8
5
votes
2 answers
Is `grep -P` (Perl/Python regex) portable on most linux distributions
I prefer (Perl/Python Compatible Regular Expressions) regular expressions.
man grep:
...., but only work if pcre is available in the system
Is this supported on the most common linux distributions?
I don't care for freebsd, solarix, busybox, ...
guettli
- 1,309
- 3
- 22
- 40
5
votes
1 answer
How to perform a multiline grep across multiple files?
I'm trying to grab this pattern wherever it occurs in multiple log files (Note:these patterns can vary greatly in size, i.e. the amount of Blahs):
Found an txt File
Blah
Blah
10019874
Blah
Blah
Processed File
Using…
blarg
- 1,565
- 7
- 21
- 33
4
votes
1 answer
pcregrep newline lookbehind assertion bug?
Attempting to use pcregrep to print the first line after a blank line. For example, contents of file
first line
second line
I need second line to be printed. Here are a few tests using the same regular expression throughout
With Python 2.7
python…
iruvar
- 16,515
- 8
- 49
- 81
3
votes
1 answer
pcregrep to find lines with surrounding white space
I have some titles that start with # (as they are markdown), and I have the two following rules:
titles (#) should have exactly two newlines lines above and one underneath
subtitles (##, ### and so forth) should have exactly one blank line above…
Øistein Søvik
- 65
- 4
3
votes
3 answers
Print up to (and including) the nth occurence of a pattern in a line
Let's say I have multiple lines similar to below in a file.
Turbo is a cat. cats are good. cats are not dog.
Coco is a black cat. cats are furry. cats are not dog.
now, if want to grep all the ^.*cat but want to specially mention to capture till…
Krishna Gupta
- 133
- 1
- 5
2
votes
1 answer
Capture output of a command that get stuck
I am trying to use regex for capturing some text pattern in an ouput of a command and create an array list_mqs. The problem is that this previous command get stuck and never terminates. So, when I use a pipeline | egrep, never starts the egrep…
dcubaz
- 23
- 5
2
votes
3 answers
Grep Lines from File with spaces
I have File which contains Records
qwe.google.com IN A 1.1.1.1
qwe.google.com IN {uneven-space} A{space}1.1.1.1
qwe.google.com IN CNAME asd.google.com
I need to grep all the lines which contains IN A, as it contains uneven spaces in…
user416391
- 43
- 1
- 4
1
vote
0 answers
pcre2grep -I not to fulfill the binary exclusion
How is pcre2grep -I not working and fulfilling the binary exclusion and preventing its search, as did:
$ pcre2grep -I 'cv' .
still search and output cv found in a binary
Please help solve how the correct
user536152
1
vote
3 answers
How to replace a line in text using RegEX?
The problem I have is that is trying to match both sets of delimiter (above and below)
I'm trying to match only the second part of the delimiter below (bolded).
This is so I can add a new version made on the same day to multiple files. Using perl,…
Javier Vazquez
- 11
- 2
1
vote
2 answers
pcregrep excluding multiple lines regexp eats one more line than needed
I want to filter out all lines starting with banana and all lines starting with a space after banana lines. I am using pcregrep. Consider the following file fruits.txt:
apple
banana starts matching
this line should match
this too
and…
ars
- 343
- 2
- 11
1
vote
1 answer
regexp: non-empty line followed by "From "
I'm in the process of migrating my Mbox format emails to the Maildir format.
To this end I use mb2md which works great.
Nevertheless I've just come to realize that sometimes in my Mbox folders a blank line does not appear right before the "From "…
Rene
- 43
- 4
1
vote
3 answers
How to cat a file with "or" options
I have a file name like
/etc/auto.abc on server 1
/etc/auto.def on server 2
/etc/auto.ghi on server 1
I am writing a single script for all servers and in that I want to cat the file.
Example: cat /etc/auto.abc or /etc/auto.def or /etc/auto.ghi. It…
venella
- 25
- 4
1
vote
2 answers
Comment particular lines using regular expression and sed
I have a very big verilog file(~350 MiB). In that, I want to comment particular module names.So i took a sample file and tried my regular expression on it.
Sample file(abc) :-
module util_minor_rev_id(minor_rev);
output [3:0] minor_rev;
wire [3:0]…
dev vaibhav
- 11
- 2
0
votes
0 answers
Using pcregrep to search for exact matches of multiline string
I am trying to search a directory using pcregrep. I want to search using a long, multi-line string. Basically, I am trying to look through multiple code bases for plagiarism. So I want to be able copy/paste a code block from some code, and then…
Lee Morgan
- 101
- 1