Re: substituing $1 one time but not the other
- From: Barry Margolin <barmar@xxxxxxxxxxxx>
- Date: Wed, 27 Sep 2006 14:23:55 -0400
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 ***
.
- References:
- substituing $1 one time but not the other
- From: patrice
- substituing $1 one time but not the other
- Prev by Date: Re: substituing $1 one time but not the other
- Next by Date: Re: substituing $1 one time but not the other
- Previous by thread: Re: substituing $1 one time but not the other
- Next by thread: Re: substituing $1 one time but not the other
- Index(es):
Relevant Pages
|