Re: substituing $1 one time but not the other



In article <451aaa63$0$1959$626a54ce@xxxxxxxxxxxx>,
"patrice" <patrice_labracherie_nospam@xxxxxxx> wrote:

Hello

I want to get the name of a mail file using its message ID.
I 'm using :
grep '^Message-ID: <my id>$' myfolder/* | awk -F ':' '{print $1;}'
and it work fine.
now i want to put this line in a shell script with 2 params: myid and
myfolder

so :
grep '^Message-ID: <$1>$' $2/* | awk -F ':' '{print $1;}'

but it does not work because of the awk argument 'print $1 ' .
the command line is substitued by
grep '^Message-ID: <myid>$' myfolder/* | awk -F ':' '{print myid;}'

how can i tell the shell to not substitute the print $1 ?????

Actually, the command line that's being executed is:

grep '^Message-ID: <$1>$' myfolder/* | awk -F ':' '{print $1;}'

The reason is that single quotes prevent variable substituion, so $1
isn't being replaced in the grep argument. So you need to use double
quotes around the grep argument:

grep "^Message-ID: <$1>\$" myfolder/* | awk -F ':' '{print $1;}'

BTW, you don't need to use awk to get the filename, just use the -l
option to grep to make it print out just the names of the files with
matching lines.

--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.



Relevant Pages

  • Re: Grep
    ... same request I get the sent mail file containing Gamblesby in the message ... What am I doing wrong with grep please? ... not a standard part of any distro. ...
    (uk.comp.os.linux)
  • Re: Grep
    ... same request I get the sent mail file containing Gamblesby in the message ... What am I doing wrong with grep please? ...
    (uk.comp.os.linux)
  • Re: Grep
    ... same request I get the sent mail file containing Gamblesby in the message ... What am I doing wrong with grep please? ... martin@ | Martin Gregorie ...
    (uk.comp.os.linux)
  • Re: HOWTO: output newline character with gres?
    ... gres = grep and substitute ... Sounds like sed with training wheels. ... Christopher Mattern ...
    (comp.unix.shell)
  • Re: Grep
    ... request I get the sent mail file containing Gamblesby in the message within ... What am I doing wrong with grep please? ...
    (uk.comp.os.linux)