Re: Quick grep question



On Mon, 27 Feb 2006 13:17:19 -0500, Chris F.A. Johnson wrote:
On 2006-02-27, Samik R wrote:
Hello,

I am trying to match couple of lines using grep. Assuming my file
has following 3 lines:
inx23r678
inx34r54
inx23_44

I want the lines with inx<some digits>r<some digits>, not the
underscore ones. I am trying this:
cat file|grep "inx[0-9]+r"
which is not working. But,
cat file|grep "inx[0-9]*r"

is working. I thought '+' matches with 1 or more occurrences, so the
first one should work too. Where am I going wrong?

First, you don't need cat; second, you need to escape the plus
sign:

grep "inx[0-9]\+r" file
[...]

Neither + nor \+ are BRE operators, so are not supposed to work
with grep. Some grep implementations such as GNU grep recognise
\+ as an extension.

What is standard BRE is \{1,\} (one or more occurrences of the
previous pattern).

+ is a standard ERE operator, -E is a standard option to grep to
understand a pattern as an ERE.

--
Stephane
.



Relevant Pages

  • Re: Novell Desktop Linux 10: getting closer to a toss up between Linux & Windows?
    ... On the other hand Linux has a well known (and sort of (almost) standardized ... But /video has become a sort of standard I think. ... I use 'locate' and 'grep' many times a day. ... As you have discovered finding something across many disk and partitions with so many giga bytes ...
    (comp.sys.ibm.pc.hardware.chips)
  • Re: Suffix allowed on expressions?
    ... integer can be typecasted to a pointer and the result ... text version of the C standard and grep. ... the word "typecast" appears nowhere in the standard. ...
    (comp.lang.c)
  • Re: "Tailing" grep (Was: cat and grep without destroying file)
    ... like to reopen a discussion about a very similar tool: a 'grep' that ... parameter that isn't there in this example) it listens on its standard ... input stream is being redirected to be the output from from 'tail'. ... Of course, this halts execution of a script until 'grep' exits, so it's ...
    (Ubuntu)
  • Re: [Hebrew] dagesh qal - special case question
    ... Standard (i.e., non-MS) regular expressions? ... hence quite similar to sed or grep. ... Prev by Date: ...
    (sci.lang)
  • Re: Grep
    ... same request I get the sent mail file containing Gamblesby in the message ... What am I doing wrong with grep please? ... not a standard part of any distro. ...
    (uk.comp.os.linux)