Groups | Search | Server Info | Login | Register
Groups > alt.comp.lang.shell.unix.bourne-bash > #269
| From | "Michael F. Stemper" <mstemper@gmail.com> |
|---|---|
| Newsgroups | alt.comp.lang.shell.unix.bourne-bash |
| Subject | Re: Escaping grep |
| Date | 2021-04-17 11:06 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <s5f12i$bsm$1@dont-email.me> (permalink) |
| References | <s0ujo2$1i0$1@dont-email.me> <20210417153619.6d991200@lorien> |
On 17/04/2021 08.36, bodiccea wrote:
> On Sun, 21 Feb 2021 15:35:55 -0600, "Michael F. Stemper"
> <mstemper@gmail.com> wrote:
>
>> I wanted to see which LaTeX packages I was using for a particular
>> project, so I did:
>>
>> user@host$ grep -h "\\usep" *tex | sort | uniq
>> % \usepackage{array} % for math mode columns in tabular
>> % \usepackage{graphicx}
>> % \usepackage{longtable}
>> % \usepackage{mathrsfs} % for mathscr
>> % \usepackage{tikz-cd} % for commutative diagrams
>> \usepackage{amsmath} % for implication and align*
>> \usepackage{amssymb} % for black-board set names
>> \usepackage{fancyhdr}
>> \usepackage{geometry}
>> \usepackage{parskip}
>> user@host$
>>
>> However, that showed unused packages as well. So I tried
>> anchoring my grep to the beginning of the line, and got:
>>
>> user@host$ grep -h "^\\usep" *tex | sort | uniq
>> user@host$
>>
>> Why isn't this working? What am I overlooking? How
>> should I have said it?
>
> There is no issue with the grep expression itself. The problem is
> with bash handling of strings: You use " (double quotes) around
> your expression, asking bash to interpret the contents.
>
> bash will replace "^\\usep" with "^\usep" *before passing it to grep*.
> grep then will remove special meaning for following char (u) - no
> special meaning in this case.
> The result is that grep will just look for lines starting with "u".
Thank you. I've been using various *IX variants for three decades now
and I still can't get the single-quote v double-quote distinction
through my head.
> You have 2 solutions:
> 1) use quotes instead of double quotes: '^\\usep', so that bash does
> not change anything.
Works fine, lasts a long time!
> Sorry for late answer, I just joined this group.
>
> And yes, it is a pure 'bash' question, not a 'grep' question as I saw in
> another answer :)
Thought so!
--
Michael F. Stemper
Outside of a dog, a book is man's best friend.
Inside of a dog, it's too dark to read.
Back to alt.comp.lang.shell.unix.bourne-bash | Previous | Next — Previous in thread | Find similar
Escaping grep "Michael F. Stemper" <mstemper@gmail.com> - 2021-02-21 15:35 -0600
Re: Escaping grep Lewis <g.kreme@kreme.dont-email.me> - 2021-02-22 06:36 +0000
Re: Escaping grep bodiccea <bodiccea@gmail.com> - 2021-04-17 15:36 +0200
Re: Escaping grep bodiccea <bodiccea@gmail.com> - 2021-04-17 17:58 +0200
Re: Escaping grep "Michael F. Stemper" <mstemper@gmail.com> - 2021-04-17 11:08 -0500
Re: Escaping grep bodiccea <bodiccea@gmail.com> - 2021-04-17 19:21 +0200
Re: Escaping grep "Michael F. Stemper" <mstemper@gmail.com> - 2021-04-17 11:06 -0500
csiph-web