Re: substituing $1 one time but not the other



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.
.



Relevant Pages