Trying to take file numbers from a file, pass them to sed to change strings in corresponding lines

I have a bunch of file numbers in the file 'test':

I'm trying the above command to change all the instances of "H" to "Na+" in the file testsds.pdb at the line numbers indicated in the file 'test'. I've tried the following and various similar alternatives but nothing is working:

cat test | while read line; do line=$line"s"; sed -i "$line/H  /Na+/" testsds.pdb >> well ; done

Any help would be greatly appreciated.

Give us an example of the current data and expected changes...we shall try

1 Like

Try:

awk 'NR==FNR{a[$0]=1;next}a[FNR]==1{gsub ("H","Na+")}1' test testsds.pdb
1 Like
awk 'NR==FNR{a[$0]=1;next}a[FNR]==1{gsub ("H","Na+")}1' test testsds.pdb

^ works flawlessly, thank you.