Muz
Muz

Reputation: 73

Perl Regex segregating text chunks

I have a long text file like:

COMPONENT;SCALAR;VALUE
point1/point2 - Value Value Value
point1/point2 - Value Value Value
point1/point2 - Value Value Value
point1/point2 - Value Value Value
point1/point2 - Value Value Value
point1/point2 - Value Value Value
point1/point2 - Value Value Value

COMPONENT;SCALAR;VALUE
point3/point4 - Value Value Value
point3/point4 - Value Value Value
point3/point4 - Value Value Value
point3/point4 - Value Value Value
point3/point4 - Value Value Value
point3/point4 - Value Value Value
point3/point4 - Value Value Value

Now I have already extracted all the unique values of 'point3/point4' type of values .. Now what I have to do is to extract the whole data chunk .. e.g From COMPONENT;SCALAR ----> \n\n (There are two new lines at end of block). Now what I tried to do is

string =~ /(COMPO\S\spoint1\/point2)(.+?)(COMP)/s;
print $2;

but it doesn't work. The match should match only till the first '\n\n' and not be greedy to capture max. Any one liner would be greatly appreciated.

Upvotes: 1

Views: 82

Answers (1)

Miller
Miller

Reputation: 35208

Using a perl one liner.

perl -00 -ne 'print if m{point1/point2};' data.txt

The only trick is from perlrun using -00 for paragraph mode.

Upvotes: 1

Related Questions