[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep

From: Chris Jones
Subject: Re: grep
Date: Sat, 25 Apr 2009 11:44:21 -0400
User-agent: Mutt/1.5.13 (2006-08-11)

On Sat, Apr 25, 2009 at 04:12:26AM EDT, Ralf Wildenhues wrote:
> * Chris Jones wrote on Sat, Apr 25, 2009 at 10:02:39AM CEST:
> > 
> > How do I grep a bunch of documents for all occurrences of "words" such
> > as '.bashrc', '.bash-history' etc. ..?
> With extended regular expressions that should always be possible,

>   grep -E '(^|[^[:alpha:]0-9_])(.bashrc|.bash-history)($|[^[:alpha:]0-9_])'

Thanks much for providing a more general solution - although it doesn't
quite do what I had in mind - match file names that start with '.bash'.

After tinkering with "basically" the same ideas (I think).. I quickly
suspected that this was not going to be trivial (at least for me) and
gave up - thinking that.. 

(1) I would probably get it wrong anyway... and what's worse not even
realize it.

(2) that I'd end up with something so convoluted as to be impractical.

Compare with:

$ cat /tmp/the
The other day I met Theo in the park.
$ grep -i -w --color=auto the /tmp/the
The other day I met Theo in the park.
^^^                         ^^^

(with carets marking colorized words - hope they stay where I put them)

Since most greps I do are case insensitive and I find color highlighting
useful, 'g' is aliased to most of the above and I would type:

$ g -w /tmp/the | b                   # 'b' is aliased to 'less -R'

And since the file(s) whose content I am searching may have names that
are somewhat longer and harder to type than '/tmp/the' and are usually
not very far back in my bash history, under most circumstances, I would
just need to hit "Alt+." a few times to avoid having to type the file

What initially prompted me to post was that I was a bit surprised that
given the central role of dot files in *nix culture, looking for
occurrences of such sequences of characters in a text file would require
putting together a fairly complex regular expression at the bash prompt.

If I was looking for an email that I only remember contains references
to a dot file such as '.bashrc' - or was it '.bash_profile"? - that I'm
pretty sure I still have in the mailing list's mbox, I would be tempted
to do it in two passes because I would want something "quick and dirty"
so as to avoid being sidetracked and risk forgetting why I looking for
the email in the first place :-)

Something like:

$ egrep '[[:space:]].bash' ~/mail/gnu-mbox  # found the email? if not...

$ egrep '^.bash' ~/mail/gnu-mbox 

Thank you for your interest. 

It will certainly encourage me to look further into grep and regular


reply via email to

[Prev in Thread] Current Thread [Next in Thread]