On Sun, 8 Jul 2001, Matt Adams wrote:
Matt,
If your intention is to get the only the first line in the file
that matches the pattern, you are going about it the wrong way. First of
all, the '/<reg exp>/' syntax is specific to sed and awk - and it doesnt
apply to grep or egrep. Secondly, the "quantifiers" (as you call them :
they are more accurately described as repetition operators for regular
expressions), apply to the expression. Which means, if you were saying
'(abc){3}' you are trying to match the string 'abcabcabc' NOT the first
three lines that match 'abc' .
To accomplish your ends, one could try :
grep -E -e 'cjim' file | head -n 1
or
awk '/cjim/{print $0;exit}' file
or
sed '/cjim/!d;/cjim/q' file
I'm sure there are other solutions too.
Regards,
Kenneth
> Hello,
>
> I have an ASCII file with duplicate entries throughout the file (such as
> the string 'cjim' or 'buffalo') that I am parsing via grep. I wish to
> retrieve only one match however using the parameters
>
> $ grep -E -e "/cjim/{1}"
>
> produces no results. I've never used the {+,?,*,{n,m}} quantifiers before;
> how should I be tying them into a regexp?
>
>
> And comments or suggestions are greatly appreciated.
>
> Thanks,
>
> Matt
>
> --
> Matt Adams (ICQ 109490925)
> Personal: <[EMAIL PROTECTED]>
> Scouts Canada: <[EMAIL PROTECTED]> (no longer active)
> Altair Electronics: <[EMAIL PROTECTED]> (no longer active)
> -
> To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
> the body of a message to [EMAIL PROTECTED]
> Please read the FAQ at http://www.linux-learn.org/faqs
>
-
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.linux-learn.org/faqs