Re: scripting question
On Wed, Apr 16, 2003 at 02:05:52PM +0100, Colin Watson wrote:
> On Wed, Apr 16, 2003 at 03:40:42PM +0200, David Jardine wrote:
> > On Wed, Apr 16, 2003 at 12:23:46PM +0100, Colin Watson wrote:
> > > On Tue, Apr 15, 2003 at 07:23:06PM -0700, Alvin Oga wrote:
> > > > -- and be careful, that what you type on a command line will NOT
> > > > necessarily work in a bash script
> > > >
> > > > root# ls -la /home/foo | grep -iv "ignore|this|and|that"
> > > >
> > > > will need to be 'escaped' in some scripts and not others
> > >
> > > That's wrong just to start with. Use egrep if you want to use '|' for
> > > alternatives. With grep, use '\|', and put single quotes around it, not
> > > double. Double quotes are asking for trouble unless you explicitly want
> > > their expansion effects.
> > Well,
> > grep foo "ignore\|this\|and\|that" -v
> > works for me but
> > grep foo 'ignore\|this\|and\|that' -v
> > doesn't.
> Neither of those is right anyway (you've got the pattern and the
> filename the wrong way round), so perhaps you could paste exactly what
> you're doing?
Oops, sorry. Yes, I did get them wrong way round.
zcat logs.gz|grep "200\|302\|304" -v|...
or something similar does enable me to isolate odd
entries, whereas single quotes, with or without the
backslashes, don't work.
> (Actually, I was wrong anyway; \| doesn't become | inside double quotes,
> although it *does* expand differently in ways which are often relevant
> to regular expressions. See QUOTING in bash(1).)
> Colin Watson [email@example.com]
> To UNSUBSCRIBE, email to firstname.lastname@example.org
> with a subject of "unsubscribe". Trouble? Contact email@example.com
"Running Debian/GNU Linux and
loving every minute of it." -Sacher M.