Read each line in fileA, replace in all files with matching filename

Hello,
I supposed that I asked the similar question but I could not have found it when I search on our forum.

EXYU+:

EXYU%3A+HRT+1
EXYU%3A+HRT+2
EXYU%3A+HRT+3

EXYU_url:

#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/YYYY?profile=htsp7777.ts
#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/YYYY?profile=htsp7778.ts
#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/YYYY?profile=htsp7779.ts

DE+:

DE%3A+RTL+1
DE%3A+RTL+2
DE%3A+RTL+3

DE_url:

#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/YYYY?profile=htsp7777.ts
#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/YYYY?profile=htsp7778.ts
#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/YYYY?profile=htsp7779.ts

Other files are FR+, FR_url, NO+,NO_url,CA+,CA_url, .........

Expected output:

EXYU_final:

#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/EXYU%3A+HRT+1?profile=htsp7777.ts
#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/EXYU%3A+HRT+2?profile=htsp7778.ts
#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/EXYU%3A+HRT+3?profile=htsp7779.ts

DE_final:

#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/DE%3A+RTL+1?profile=htsp7777.ts
#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/DE%3A+RTL+2?profile=htsp7778.ts
#SERVICE 1:0:1:0:0:0:0:0:0:0:http%3A//xxxx%3Ayyyy@mmmm%3A55555/stream/channelname/DE%3A+RTL+3?profile=htsp7779.ts

And also I need output for FR+, FR_url, NO+,NO_url,CA+,CA_url, .........

I wonder if there is a simple solution. I searched similar solutions and I am not familiar with perl . I would appreciate if it could be simple with sed as I may need to update it according to my requirements in the future.

Many thanks
Boris

No Perl? That's too bad. I do not see a reason for sed .

while read -r replacement && read -r line <&3; do
    #echo $line | sed s/YYYY/"$replacement"/ # for reference purposes.
    echo ${line/YYYY/$replacement}
done < ${1} 3<${2}
./myscript  EXYU+ EXYU_url > EXYU_final
2 Likes

Hello Aia,

This field:

while read -r replacement && read -r line <&3;

And this field:

done < ${1} 3<${2}

helped me too much.

Sorted out

Many thanks
Boris