grep for a "`g'"? (gives an "Unmatched `" err)

  • Follow


SUBJECT: How to grep for a "`g'"?  (gives an "Unmatched `" err)


You know how many documents do, uh, "2nd-level:" quoting around
words or phrases by using *single* quotes, but not like this:"

               'a single-quoted phrase'

but like this:

               'a single-quoted phrase`

using a back-quote to close it off.


So, I want to find (grep) all occurrences of
        'g`
in a file.

Here's what I've tried so far -- with no success:



| 317 ====> egrep -n  "`g'" `cat userdocs.nam` > ! t5.loc
| Unmatched `.
| 318 ====> egrep -n  "\`g\'" `cat userdocs.nam` > ! t5.loc
| Unmatched `.
| 319 ====> egrep -n  '[']g[`]' `cat userdocs.nam` > ! t5.loc
| Unmatched `.
| 320 ====> egrep -n  "[']g[`]" `cat userdocs.nam` > ! t5.loc
| Unmatched `.


Oh, I'm using tcsh.




So, here's with sh (Bourne):

468 ====> sh
$ 
$ egrep -n  "`g'" `cat userdocs.nam` 
g": not found
usr_01.txt:1:*usr_01.txt*	For Vim version 6.3.  Last change: 2004 May 01
usr_01.txt:2:
usr_01.txt:3:		     VIM USER MANUAL - by Bram Moolenaar
usr_01.txt:4:
usr_01.txt:5:			      About the manuals
usr_01.txt:6:
usr_01.txt:7:
usr_01.txt:8:This chapter introduces the manuals available with Vim.  Read this to know the
usr_01.txt:9:conditions under which the commands are explained.

$ 
$ egrep -n  "\`g\'" `cat userdocs.nam` | head
$ 
$ egrep -n  '[']g[`]' `cat userdocs.nam` | head
> 
> 
$ echo HUH?
HUH?
$ 
$ 
$ egrep -n  "[']g[`]" `cat userdocs.nam` | head
]: not found
egrep: Unmatched [ or [^
$ 
$ 
$ 


Any ideas?

   (please do first try your solutions, if any:
      this quoting-stuff is a real bear!)


Thanks,

David


0
Reply dkcombs 9/6/2007 12:15:48 AM

On 5 Sep 2007 20:15:48 -0400 dkcombs@panix.com (David Combs) wrote:
> SUBJECT: How to grep for a "`g'"?  (gives an "Unmatched `" err)
>
>
> You know how many documents do, uh, "2nd-level:" quoting around
> words or phrases by using *single* quotes, but not like this:"
>
>                'a single-quoted phrase'
>
> but like this:
>
>                'a single-quoted phrase`
>
> using a back-quote to close it off.

they don't do that.  they `do this', or ``this'', to distinguish between
opening and closing quotes.

anyway, using double quotes interprets your args so you simply have to
escape the backquote: "\`g'".

Or use single quotes but then you have to escape the quote you are
trying to match: '`g\''.

-frank
0
Reply Frank 9/6/2007 12:50:26 AM


On 5 Sep 2007 20:15:48 -0400, dkcombs@panix.com (David Combs) wrote:
> SUBJECT: How to grep for a "`g'"?  (gives an "Unmatched `" err)
>
> You know how many documents do, uh, "2nd-level:" quoting around
> words or phrases by using *single* quotes, but not like this:"
>
>                'a single-quoted phrase'
>
> but like this:
>
>                'a single-quoted phrase`
>
> using a back-quote to close it off.

Escape your backquotes; when unescaped, they are interpreted by the
shell as the start of inline commands to be substituted by their output.

For example, look at the output of:

$ date
Thu Sep  6 04:22:19 EEST 2007
$ echo +++ "`date`" +++
+++ Thu Sep  6 04:22:31 EEST 2007 +++
$ echo +++ "\`date'" +++
+++ `date' +++
$

Note the way the actual output of _running_ the date(1) utility is
substituted in the second command.

Note how this substitution doesn't happen in the third command.

HTH,
Giorgos

0
Reply Giorgos 9/6/2007 1:23:41 AM

In article <87fy1sk2n6.fsf@kobe.laptop>,
Giorgos Keramidas  <keramida@ceid.upatras.gr> wrote:
>On 5 Sep 2007 20:15:48 -0400, dkcombs@panix.com (David Combs) wrote:
>> SUBJECT: How to grep for a "`g'"?  (gives an "Unmatched `" err)
>>
>> You know how many documents do, uh, "2nd-level:" quoting around
>> words or phrases by using *single* quotes, but not like this:"
>>
>>                'a single-quoted phrase'
>>
>> but like this:
>>
>>                'a single-quoted phrase`
>>
>> using a back-quote to close it off.
>
>Escape your backquotes; when unescaped, they are interpreted by the
>shell as the start of inline commands to be substituted by their output.
>
>For example, look at the output of:
>
>$ date
>Thu Sep  6 04:22:19 EEST 2007
>$ echo +++ "`date`" +++
>+++ Thu Sep  6 04:22:31 EEST 2007 +++
>$ echo +++ "\`date'" +++
>+++ `date' +++
>$
>
>Note the way the actual output of _running_ the date(1) utility is
>substituted in the second command.
>
>Note how this substitution doesn't happen in the third command.
>
>HTH,
>Giorgos
>

Thanks to both of you for your answers.

Problem is, I guess I mis-specified the problem:
I believe that you guys were addressing how to *write*
that quoted-q text such that later on an egrep
can find it.

The actual problem is that the text containing the quoted-q
is *someone else's* -- it's *already* writen (actually, it's
an .info-file that I'm searching for that q-thing.

So, the question becomes "how to write a REGEXP that will
find them?

Any clues?

Thanks!

David


PS: I suppose I could try perl, with it's nifty additional
quoting constructs, where you can choose your own string-delimiter.

Although maybe it'd still catch you in the regular-expression
parser?

D.



0
Reply dkcombs 9/15/2007 5:58:54 PM

On Sat, 15 Sep 2007 17:58:54 +0000 (UTC)
dkcombs@panix.com (David Combs) wrote:

> In article <87fy1sk2n6.fsf@kobe.laptop>,
> Giorgos Keramidas  <keramida@ceid.upatras.gr> wrote:
> >On 5 Sep 2007 20:15:48 -0400, dkcombs@panix.com (David Combs) wrote:
> >> SUBJECT: How to grep for a "`g'"?  (gives an "Unmatched `" err)
> >>
> >> You know how many documents do, uh, "2nd-level:" quoting around
> >> words or phrases by using *single* quotes, but not like this:"
> >>
> >>                'a single-quoted phrase'
> >>
> >> but like this:
> >>
> >>                'a single-quoted phrase`
> >>
> >> using a back-quote to close it off.
> >
> >Escape your backquotes; when unescaped, they are interpreted by the
> >shell as the start of inline commands to be substituted by their
> >output.
> >
> >For example, look at the output of:
> >
> >$ date
> >Thu Sep  6 04:22:19 EEST 2007
> >$ echo +++ "`date`" +++
> >+++ Thu Sep  6 04:22:31 EEST 2007 +++
> >$ echo +++ "\`date'" +++
> >+++ `date' +++
> >$
> >
> >Note the way the actual output of _running_ the date(1) utility is
> >substituted in the second command.
> >
> >Note how this substitution doesn't happen in the third command.
> >
> >HTH,
> >Giorgos
> >
> 
> Thanks to both of you for your answers.
> 
> Problem is, I guess I mis-specified the problem:
> I believe that you guys were addressing how to *write*
> that quoted-q text such that later on an egrep
> can find it.
> 
> The actual problem is that the text containing the quoted-q
> is *someone else's* -- it's *already* writen (actually, it's
> an .info-file that I'm searching for that q-thing.
> 
> So, the question becomes "how to write a REGEXP that will
> find them?
> 
> Any clues?
> 
> Thanks!
> 
> David
> 
> 
> PS: I suppose I could try perl, with it's nifty additional
> quoting constructs, where you can choose your own string-delimiter.
> 
> Although maybe it'd still catch you in the regular-expression
> parser?
> 
> D.
> 
> 
> 

/home/malcolml> cat userdocs.nam
a test 'just testing`
testing
naming`
qwerty
xxxx`1
/home/malcolml> egrep -n 'g`' userdocs.nam
1:a test 'just testing`
3:naming`
/home/malcolml> 

-- 
Cheers Malcolm ��� (Linux Counter #276890)
SLED 10.0 SP1 x86_64 Kernel 2.6.16.53-0.8-smp
up 5 days 17:59, 4 users, load average: 0.08, 0.07, 0.03
0
Reply Malcolm 9/15/2007 6:39:03 PM

4 Replies
344 Views

(page loaded in 0.096 seconds)

Similiar Articles:













7/26/2012 10:15:38 AM


Reply: