Search and replace is not working by sed or awk

Hi ,

I have one file and in this file i have one like

TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD*;PPJERPTD*;PPJERPT*;PRBSUMM*;:

i want to replace this line with the following line

TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD*;PPJERPTD*;PPJERPT*;PRBSUMM*;AAC185R1,BAR0111*;:

my code is not working , i m using following code;

Str1="TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD*;PPJERPTD*;PPJERPT*;PRBSUMM*;:"
Str2="TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD*;PPJERPTD*;PPJERPT*;PRBSUMM*;AAC185R1,BAR0111*;:"
awk -v s1="$Str1" -v s2="$Str2" '{sub(s1,s2)}1' test > test1

in the new file test1 having the same data as test.
I tried with sed as well but it is not working .

Please suggest how to do it.

Looking at the string you want to replace I can see there is only small change at the end of line.. considering it remains same..

 
awk -F":" '/^TEST1 KEY0/{print $1"AAC185R1,BAR0111*;:"}' filename

in this example there are only two new entries, however it could me more than that, thats why i am passing it through variable.

You could use \* instead of * for Str1, similarly escape other metacharacters as needed. I know that's a bother, but certainly doable. Not sure what else to suggest that would work.

$ cat input
TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD*;PPJERPTD*;PPJERPT*;PRBSUMM*;:
$ cat ./test-2.sh
Str1="TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD\*;PPJERPTD\*;PPJERPT\*;PRBSUMM\*;:"
Str2="TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD*;PPJERPTD*;PPJERPT*;PRBSUMM*;AAC185R1,BAR0111*;:"
sed "s/$Str1/$Str2/" input
$ ./test-2.sh
TEST1 KEY0=AAC040R1;AAC041R1ISE;AAC041R2ISE;AAC370R1;ADR0500;ADR0600;AME245R1;AME245R2;BAP0135;BAP0300;PPINVDTD*;PPJERPTD*;PPJERPT*;PRBSUMM*;AAC185R1,BAR0111*;:

the value in these variable is not constant, it will change everytime and I do not know where i will have * . There is a command that fetching the value for these two variable.

Is there any way we can do it.