1

I am a beginner of using programming commands.

Why {2} is not functional after ([^\t]*\t) in macOS terminal?

Is there any website providing Perl RegEx which works in mac? Thanks!

  • grep -p "^([^\t]*\t){2}mypattern\t" textfile.txt does not return an error on macOS 10.12. Are you seeing an error message or is your regex not matching as you expect? – Graham Miln Aug 30 '17 at 8:02
1

RegExPlanet offer a Regular Expression Test Page for Perl. This page works with Safari on macOS 10.12.

You may find that grep included with macOS does not include all the functionality you want. If so, try installing grep from Homebrew or MacPorts.

1

bsd grep does not use perl regular expressions. Please read man grep and note what the -p option does. Again, man 7 re_format explains how regex works in macOS with tools such as grep and sed.

In your regular expression the character \t is not interpreted as the tab control character. So you will need to type the literal tab character ( control + v, tab ) instead -

grep -E '^([^   ]*      ){2}mypattern ' FILE

or you can use ansi-c quoting (Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard.) -

grep -E $'^([^\t]*\t){2}mypattern\t' FILE

You can also use perl directly -

perl -ne  'print if /^([^\t]*\t){2}mypattern\t/' FILE

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .