1

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 "^"

Community
  • 1
  • 1
Kiran Vemuri
  • 2,762
  • 2
  • 24
  • 40
  • 2
    Ehm just surround expression with / – Ja͢ck Jun 13 '12 at 12:44
  • 1
    It's difficult to newer without knowing what you're trying to match against. It looks like syntactically valid expression and so it should run. Perhaps if you could enhance your question with examples of what you get versus what you expect? – Damian Powell Jun 13 '12 at 12:44

2 Answers2

1

i managed to work it out using PCREGREP utility

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

that did it :) thanks @Damian @jack

Kiran Vemuri
  • 2,762
  • 2
  • 24
  • 40
1

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.

clt60
  • 62,119
  • 17
  • 107
  • 194