Groups | Search | Server Info | Login | Register
Groups > comp.unix.misc > #442
| Path | csiph.com!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
| Newsgroups | comp.unix.misc |
| Subject | Re: How do you "grep" in a string when you know how it starts and how it ends? |
| Date | Wed, 24 Apr 2024 08:58:02 -0700 |
| Organization | None to speak of |
| Lines | 52 |
| Message-ID | <87a5lin46t.fsf@nosuchdomain.example.com> (permalink) |
| References | <v0b809$2cs3r$1@dont-email.me> <87edaun4fh.fsf@nosuchdomain.example.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Date | Wed, 24 Apr 2024 17:58:03 +0200 (CEST) |
| Injection-Info | dont-email.me; posting-host="8912a4ab33884690e874a0120806b9cc"; logging-data="2534126"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192O72dTVKlLFUsdEg3Mbyl" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) |
| Cancel-Lock | sha1:VMiT3Erh9VTEsYaScakl53zFNxM= sha1:sED+4sKaflVLMp2i5OT7bWp6dsI= |
| Xref | csiph.com comp.unix.misc:442 |
Show key headers only | View raw
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
> Ottavio Caruso <ottavio2006-usenet2012@yahoo.com> writes:
>> Sorry for the convoluted title, but let's say I am looking for all the
>> occurrences of "keep on *ing" in a file, so that it catches:
>>
>> keep on running
>> keep on doing
>> keep on walking
>>
>>
>> I tried:
>>
>> $ grep -i "keep on *ing" file
>
> The " *" matches zero or more spaces.
>
>> and
>>
>> $ grep -i "keep on [a-zA-Z0-9_]ing" file
>
> The "[a-zA-Z0-9_]" matches exactly one character from the set, so it
> will match "keep on xing".
>
>> but it obviously didn't work.
>
> $ grep -i "keep on [a-zA-Z0-9_]*ing" file
>
> That will match "keep on ing". If you want to match at least one
> alphanumeric before the "ing:
>
> $ grep -E -i "keep on [a-zA-Z0-9_]+ing" file
>
> This doesn't handle accented letters.
Something that can be confusing is that file matching patterns and
regular expressions are different. In a file matching pattern, "*"
matches zero or more arbitrary characters:
ls foo*.txt
In a regular expression, "*" matches zero or more occurrences of
whatever precedes it, and "." matches a single character:
ls | grep '^foo.*\.txt$'
The above two commands are nearly equivalent (there could be some
differences depending on how "ls" displays unusual characters).
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.unix.misc | Previous | Next — Previous in thread | Next in thread | Find similar
How do you "grep" in a string when you know how it starts and how it ends? Ottavio Caruso <ottavio2006-usenet2012@yahoo.com> - 2024-04-24 16:20 +0100
Re: How do you "grep" in a string when you know how it starts and how it ends? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-04-24 08:52 -0700
Re: How do you "grep" in a string when you know how it starts and how it ends? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-04-24 08:58 -0700
Re: How do you "grep" in a string when you know how it starts and how it ends? Grant Taylor <gtaylor@tnetconsulting.net> - 2024-04-24 20:19 -0500
How do you "grep" in a string when you know how it starts and how i Amessyroom@f10.n1.z38.fidonet.org (Amessyroom) - 2024-07-11 23:25 +1300
csiph-web