grep regular expressions

No replies
User offline. Last seen 2 years 12 weeks ago. Offline
Joined: 02/02/2016


I have a data file where I want to find specific lines that match the following structure: search for the start of a line, ^, followed by 0 or more characters except a tab or end of line character, [^\t\r], followed by a square bracket, \[, followed by 1 or more characters, .+, followed by a square bracket and a colon and the line ending, \]\:\r, like this:


This will find the lines I want in TextWrangler. I cannot figure out how to find these lines using grep (I want to use a grep command to do things like count lines matching this structure, and other things). Can someone please help me translate this regexp into something that grep will understand? I cannot figure out how to do it from man grep.

Also, from reading around online, it seems it might be possible to get grep to understand the same kind of regular expressions that are used in the book and in TextWrangler (grep -P?). Does anyone know if this is possible and how to do this? I use a Mac OS X Version 10.9.5.