Help needed with sed

Can someone please help me correctly frame the below sed command:

sed 's/.*/$(date +%Y%m%d)' filepattern

I have read a line of the file in filepattern variable which is like below:

P.182.MKT_DISC.*.2_1_1.*

I want to replace the last .* part with the current date in the format yyyymmdd. I have recently started using sed so please excuse me if I am making a basic mistake.

Mistake 1: you are asking sed to process a file named filepattern in the current directory.
You have to feed the standard input of sed with the variable value:

print -- "$filepattern" | sed ...
echo "$filepattern" | sed ...

Mistake 2: the s command expects a regular expression, not a raw string.
Therefore .* means any character repeated zero or more times, in other words any character sequence.
You have to escape the metacharacters and then use the metacharacter $ to anchor the expression to the end of the input string:

print -- "$filepattern" | sed 's/\.\*$/$(date +%Y%m%d)'
# echo "P.182.MKT_DISC.*.2_1_1.*" | sed "s/\*.*/$(date +%Y%m%d)/"
P.182.MKT_DISC.20090418

Thanks for replying Colemar but I still get parsing error.This is the code:

while read -r filepattern
do
echo "$filepattern" | sed 's/\.\*/$(date +%Y%m%d)'

            done < /FileCheck/2009417.txt

So I am reading a line of file into filepattern and want to change the .* with date. After taking care of RE, I still get the following error:

P.182.MKT_DISC.*.2_1_1.*
sed: Function s/\.\*/\.$(date +%Y%m%d) cannot be parsed.

Please advice.

My fault.
I forgot the closing / and the fact that single quotes are avoiding shell expansion of $.

echo "$filepattern" | sed "s/\.\*/$(date +%Y%m%d)/"

@Colemar: you're loosing your $ (s) ... :wink:

sed "s/\.\*$/$(date +%Y%m%d)/"

Thanks to you guys! My script is working as expected now.

Cheers!:b: