Skip to main content

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.

Filter by
Sorted by
Tagged with
0 votes
2 answers
116 views

Unable to grep foreign language in shell script

I am a newbie in shell scripting, I have a text which contain text in following format:- "some foreign language",'corresponding ID to text' for example:- "Назад",...
tabish's user avatar
  • 500
0 votes
0 answers
141 views

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/...
Lee Morgan's user avatar
0 votes
1 answer
511 views

How to install pcre2-tools on Rocky Linux

I am on RL v9.1. The package seems to be there (pcre2-tools-10.40-2.el9.x86_64.rpm) but yum doesn't see it: yum install pcre2-tools runner_gitlab-runner 1.4 kB/s | 1.0 kB 00:00 ...
msciwoj's user avatar
  • 371
0 votes
1 answer
206 views

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 ...
dcubaz's user avatar
  • 23
2 votes
1 answer
499 views

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 ...
dcubaz's user avatar
  • 23
0 votes
2 answers
54 views

GREP PCRE RegExp: match desired line, then match the number, then remove the commas to match digits only

With the help of https://regexr.com/ I'm trying to understand and learn grep -P. So far I managed to get this result: $ cat Dogtooth\ \[2001\,\ Lanthimos\ Yorgos\].mp4.info Filename: ...
T. Caio's user avatar
  • 129
6 votes
3 answers
6k views

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: ...
Johnny Rollerfeet's user avatar
1 vote
0 answers
672 views

Pcre2grep multiline regular expression

I'm trying to create a regular expression to match the first html of a text file with this content: garbage garbage §<html class="test1"> <div>test</div></html>§ ...
debe80's user avatar
  • 11
0 votes
1 answer
511 views

Does pcregrep (or pcre2grep) have the equivalent of grep's --max-count option?

Take the following file : aaa bbb XXX ccc ddd eee XXX fff ggg I'd like to print, with pcregrep, all lines until the first one containing XXX : aaa bbb XXX Is it possible (with pcregrep or pcre2grep) ...
ChennyStar's user avatar
  • 1,805
0 votes
2 answers
55 views

How to replace duplicated multi-line groups, e.g. from git & diff3

I'm rebasing legacy code, and finding lots of conflicts caused by scripts -- usually code formatters. The changes are simple and predictable, so I can trivially re-run the script to apply the changes ...
Steve Almond's user avatar
-1 votes
1 answer
225 views

What are the difference between `\b` vs `\S` in PCRE grep?

I know now that \b is for Word Boundaries while \s and \S is for Shorthand Character Classes where \s (lowercase) is for whitespace (space, tab, vtab, newline) and \S (uppercase) is the other way ...
Wolf's user avatar
  • 1,661
0 votes
1 answer
72 views

last match with RegEx

I do grep -oP '(?<=%28).*?(?=%29)' f.txt on the following line chr01_pilon_pilon gmap-gsnap mRNA 55846944 55847057 . + . ID=NbD052382.1.mrna1;Name=NbD052382.1;Note=cytochrome b6/f ...
user977828's user avatar
2 votes
3 answers
4k views

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 ...
user416391's user avatar
0 votes
3 answers
605 views

awk and egrep for regular expression

I am very new to unix! trying to figure out, from a fastq file how many reads have 3 or MORE As in a row? I used egrep 'A{3}' to tell me how many AAA I have. But now I want to know >= 3 AAA in a ...
Sarah's user avatar
  • 1
0 votes
1 answer
3k views

pcregrep missing from CentOS 7

I have a fresh install of CentOS 8, and the pcre package is already installed. However, the pcregrep command is not available and nowhere to be found on the filesystem. According to CentOS docs this ...
TSG's user avatar
  • 1,768
1 vote
3 answers
704 views

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 ...
Javier Vazquez's user avatar
0 votes
1 answer
624 views

How to grep Cisco interface name and all IP Addresses under that section

This is sample of Cisco config file which I get from https://resources.intenseschool.com/mpls-basic-configuration/ and modified it a little bit to make it relevent to this question. I saved it to ...
user11392987's user avatar
0 votes
1 answer
2k views

How does pcregrep works?

I have a file: This error -this -this -that [text I want] This error -asd -asfag -adsfhs [text I want] [text I want] This error -asdgsda -asdgg -gasdg I want to match to match except This error and ...
Prvt_Yadav's user avatar
  • 5,932
0 votes
1 answer
162 views

match groups with an inverted match

I need to extract with -o1 a group that is matched in lines that do not contain a string. If I use -v pcregrep does not match any groups - which is reasonable: I'm asking to group-match something in ...
Anton Maria Prati's user avatar
0 votes
3 answers
2k views

find text in files and copy to a csv

I need to extract the text in a bunch of html files (about 500K of them) The text to be copied looks like <div class='cls '>text to be copied including some<span>and <p></p><...
flish's user avatar
  • 103
0 votes
4 answers
221 views

Select lines based on lines above them

I have a list of items, from which I want to select the names of active items: item { status: "Active" properties { key_a: value } id: 42 name: "Foo" } item { status: "Disabled" ...
danijar's user avatar
  • 1,473
3 votes
1 answer
461 views

pcregrep to find lines with surrounding white space [closed]

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 ...
Øistein Søvik's user avatar
0 votes
1 answer
619 views

extract word from file using information from a subset of the file (multiple steps)

I have two large files that look like the following: File 1: NW_006502347.1 316684 NW_006527876.1 351 NW_006502151.1 27628 NW_006526579.1 232 NW_006525259.1 132 NW_006501641.1 437014 NW_006525259.1 ...
Age87's user avatar
  • 559
1 vote
2 answers
2k views

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 ...
ars's user avatar
  • 353
1 vote
1 answer
169 views

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 ...
Rene's user avatar
  • 53
0 votes
1 answer
287 views

grep command to match the character required [closed]

I am currently using this below command for getting the total snapshot usage of the storage, but this will only show the value in G not in T: # isi_classic snapshot usage | tail -n 1 | egrep -o "[+-]?...
Poo's user avatar
  • 95
0 votes
1 answer
1k views

grep pattern syntax [closed]

i have a file with names which i make with three files. i want grep 0 if the pattern is absent from any file and 1 if the pattern is present i am using this command cat X.nam |xargs -i grep -c -P '{}$...
star's user avatar
  • 605
0 votes
1 answer
98 views

how grep text upto next space?

7/04/27 10:50:17 INFO Master: Driver submitted org.apache.spark.deploy.worker.DriverWrapper 17/04/27 10:50:17 INFO Master: Launching driver driver-20170427105017-0000 on worker worker-20170427103840-...
xyz_scala's user avatar
  • 131
-1 votes
1 answer
1k views

Exclude all hidden directories with grep and pcregrep

I'm trying to exclude all hidden directories from recursive search. I think .*/\..* this should match hidden directories and this indeed works with find, however grep doesn't think so. pcregrep -rnI ...
user1685095's user avatar
1 vote
3 answers
111 views

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 /...
venella's user avatar
  • 25
1 vote
2 answers
305 views

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 ...
you_know_who's user avatar
3 votes
3 answers
4k views

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 ^.*...
Krishna Gupta's user avatar
-1 votes
1 answer
5k views

How do I use grep to search for strings that exist both on single lines and multiple lines?

I am searching large amounts of SQL scripts for data dependencies, but due to variations in the scripts, I have encountered an interesting problem. If I am searching for the word FROM, it only ...
Ben's user avatar
  • 1
5 votes
2 answers
4k views

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 ...
guettli's user avatar
  • 1,449
5 votes
1 answer
5k views

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 ...
blarg's user avatar
  • 1,605
4 votes
1 answer
1k views

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 ...
iruvar's user avatar
  • 16.8k