Kiran Vemuri
Kiran Vemuri

Reputation: 3022

perl equivalent of my regular expression to handle a multi line search

am new to regular expressions and i cant handle a regex search using grep.. so thought of trying perl

can you give a perl equivalent to the regex

^\s*\*\s*\[ \][^\*]+?(\w*\:[^\*]+\d$)|([^\*]+[.]com[.]au$)

i want to execute it on a file in linux.. a multiline search... can anyone help me out?

even an awk command that can handle my operation would do..

and am already working on this at the following links

Scope of grep with regular expressions

a regular expression to grep specific paragraphs of a file

when i use the expression as it is, it gives me: syntax error near "^"

Upvotes: 1

Views: 205

Answers (2)

clt60
clt60

Reputation: 63922

You're looking how to use the above regex with perl from commandline (one-liner)? try:

perl -nle 'print if /regex_here/' < file

e.g.

perl -nle 'print if /bin/' < /etc/passwd

will print out all lines with "bin", and

perl -nle 'print if /^\s*\*\s*\[ \][^\*]+?(\w*\:[^\*]+\d$)|([^\*]+[.]com[.]au$)/' < file

should do what you want.

Upvotes: 1

Kiran Vemuri
Kiran Vemuri

Reputation: 3022

i managed to work it out using PCREGREP utility

pcregrep -M '(^\s*\*\s*\[ \][^\*]+?(\w*\:[^\*]+\d$)|([^\*]+[.]com[.]au$))' file1

that did it :) thanks @Damian @jack

Upvotes: 1

Related Questions