a cshell problem: putting grep output into variable

a cshell problem: putting grep output into variable

Post by Guy & Gad Ber » Wed, 09 Jun 1999 04:00:00



Hi!
I have a question regarding c-shell, I hope you can help me:

I would like to put  the output from grep into a variable, so I can
parse the output.
I tried using:

set line='grep 'abcd' myfile'

but it does not work. How can I 'pipe' the output into a
variable without using a seperate file and (<$) , in order to parse it
later as a string?

Thanks in advance, Guy.

 
 
 

a cshell problem: putting grep output into variable

Post by huuha » Fri, 11 Jun 1999 04:00:00


Hi,

You have to use mark to execute the command
l.
set line=grep 'abcd' myfile

and it should work.


Quote:> Hi!
> I have a question regarding c-shell, I hope you can help me:

> I would like to put  the output from grep into a variable, so I can
> parse the output.
> I tried using:

> set line='grep 'abcd' myfile'

> but it does not work. How can I 'pipe' the output into a
> variable without using a seperate file and (<$) , in order to parse it
> later as a string?

> Thanks in advance, Guy.


 
 
 

a cshell problem: putting grep output into variable

Post by Tim J Goodw » Fri, 11 Jun 1999 04:00:00




Quote:>set line='grep 'abcd' myfile'

You need to use backquotes,which are unfortunately somtimes difficult to
distinguish from normal quotes.

    set line = `grep abcd myfile`

(In this example, you don't need to quote grep's first argument.  Of
course, you would if it contained spaces, or other characters special to
the shell.)

Tim.
--
Tim Goodwin   | `I can't believe that someone is releasing
University of | something called "Unix" without something
Leicester, UK | called "/bin/sh".' -- Randal L. Schwartz

 
 
 

a cshell problem: putting grep output into variable

Post by Charles Dem » Fri, 11 Jun 1999 04:00:00






>>set line='grep 'abcd' myfile'

>You need to use backquotes,which are unfortunately somtimes difficult to
>distinguish from normal quotes.

>    set line = `grep abcd myfile`

>(In this example, you don't need to quote grep's first argument.  Of
>course, you would if it contained spaces, or other characters special to
>the shell.)

better might be:

    set line = "`grep abcd myfile`"
or
    set line = '`grep abcd myfile`'

to save multiple consecutive embedded spaces in the grepped line.

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.

 
 
 

a cshell problem: putting grep output into variable

Post by Barry Margoli » Fri, 11 Jun 1999 04:00:00




>better might be:

>    set line = "`grep abcd myfile`"
>or
>    set line = '`grep abcd myfile`'

The first one is right, but the second one is wrong -- single quotes
prevent interpretation of *all* shell metacharacters inside, so the
backquotes won't be processed.  Doublequotes prevent interpretation of
everything except $ (for variable substitution) and ` (for command
substitution).

--

GTE Internetworking, Powered by BBN, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

a cshell problem: putting grep output into variable

Post by Keith Thompso » Tue, 15 Jun 1999 04:00:00



> Hi,

> You have to use mark to execute the command
> l.
> set line=grep 'abcd' myfile

> and it should work.

As others have pointed out, you need to use backticks (`).  The
character you used is a Latin-1 acute accent character, with a value
of 180 (0xb4), sometimes represented as M-4.  You were obviously
speaking meta-4ically.

--

San Diego Supercomputer Center  <http://www.sdsc.edu>                 <*>
One of the great tragedies of ancient history is that Helen of Troy
lived before the invention of the champagne bottle.

 
 
 

a cshell problem: putting grep output into variable

Post by Charles Dem » Tue, 15 Jun 1999 04:00:00





>As others have pointed out, you need to use backticks (`).  The
>character you used is a Latin-1 acute accent character, with a value
>of 180 (0xb4), sometimes represented as M-4.  You were obviously
>speaking meta-4ically.

God will pun-nish you for that.  :-)

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.