Re: substituing $1 one time but not the other
- From: Ed Morton <morton@xxxxxxxxxxxxxx>
- Date: Wed, 27 Sep 2006 13:16:43 -0500
patrice 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 ' .
No, it doesn't work because the shell variable $1 is inside single quotes and so won't be expanded.
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 ?????
I don't really know what you mean by that question, but everything before it seems to imply that what you to is instead of this:
grep '^Message-ID: <my id>$' myfolder/* | awk -F ':' '{print $1;}'
be able to do this:
myid="$1"
myfolder="$2"
grep "^Message-ID: ${myid}$" "${myfolder}"/* | awk -F ':' '{print $1;}'
By the way you don't need grep AND awk since awk can cheerfully do pattern matching on it's own:
myid="$1"
myfolder="$2"
awk -F: -v myid="$myid" '$0 ~ "^Message-ID: " myid "$"{print $1}' "${myfolder}"/*
Regards,
Ed.
.
- Follow-Ups:
- Re: substituing $1 one time but not the other
- From: Ed Morton
- Re: substituing $1 one time but not the other
- References:
- substituing $1 one time but not the other
- From: patrice
- substituing $1 one time but not the other
- Prev by Date: Re: Changing UnixID
- Next by Date: Re: simple alias doesn't work
- Previous by thread: substituing $1 one time but not the other
- Next by thread: Re: substituing $1 one time but not the other
- Index(es):
Relevant Pages
|