Bash incert line from 1.txt to 2.txt

i would like to insert a line from 2.txt into 1.txt between " and "

or a way of adding to the end of each line " _01_ and have the numbers
correspond to the line #

1.txt=

foofoo "" _01_
foofoo "" _02_
foofoo "" _03_
foofoo "" _04_

2.txt=

xttps://111..............................................................................Yp
xttps://222..............................................................................Yp
xttps://333..............................................................................Yp
xttps://444..............................................................................Yp

output.txt

foofoo "xttps://111..............................................................................Yp" _01_
foofoo "xttps://222..............................................................................Yp" _02_
foofoo "xttps://333..............................................................................Yp" _03_
foofoo "xttps://444..............................................................................Yp" _04_

if you could point me in the right direction i'v been looking at sed and awk thank you in advance .

awk -v qq='"' 'FNR==NR{a[FNR]=$0;next} {sub(qq qq, qq a[FNR] qq)}1' klein2.txt klein1.txt

thank you vgersh99
that worked almost perfect except when awk comes across & in the html line it replaces & with ""

care to provide a sample record where the code breaks?

Sent from my Lenovo B8080-F using Tapatalk

sorry about the xxx's but i'm not allowed to post html yet

before awk what the xttps should look like

xttps://www.xxxxxx.com/xxxxxx?v=m1PRD0kMgI8&list=PLCAAA4629624F20D8&xxxxxx=1

after awk what the xttps looks like

./xxxxx_xxxxx.pl "xttps://www.xxxxxx.com/xxxxxx?v=m1PRD0kMgI8""list=PLCAAA4629624F20D8""xxxxxx=1" _01_

i tryed using sed

sed 's/""/&/g' ouyput > overnight.sh

but it didn't work, but i can use find and replace in pluma , would like to automate it.

a different approach:

awk -F'"' 'FNR==NR{a[FNR]=$0;next} {$2=a[FNR]}1' OFS='"' klein2.txt klein1.txt

thank you vgersh99
that worked perfect

1 Like