I want to replace a column in one file with a single value from another file using unix.
File 1 is a pdb file, structured like this:
HETATM 14 H4B FAD B 600 95.544 50.240 71.308 1.00 -1.00 H
HETATM 14 H4B FAD B 600 95.544 50.240 71.308 1.00 -1.00 H
I want to replace column number 11 with a single value which is stored in another file (File 2) which looks like this:
[1, 27, -81.883, 4.0]
[3, 38, -66.122, 12.0]
[3, 57, -62.134, 12.0]
I want the value from File 2 (column 3 of line 1) to be the in column 11 of File 1, so that File 1 looks like this:
HETATM 14 H4B FAD B 600 95.544 50.240 71.308 1.00 -81.88 H
HETATM 14 H4B FAD B 600 95.544 50.240 71.308 1.00 -81.88 H
I can replace column 11 of File 1 with a single value (2 in this case) using:
awk '{$11=2}1' File1
and I have found code like this from https://stackoverflow.com/questions/7846476/replace-column-in-one-file-with-column-from-another-using-awk
awk 'FNR==NR{a[NR]=$3;next}{$2=a[FNR]}1' f2 f1
However I believe I should be using a combination of awk and sed to get the value I want out of File 2 into File 1.
Code below gives me first line of column 11:
awk 'FNR==1{print $11}'
I simply cannot figure out how to combine the two things.
I cannot search by value because values change with every dataset I have (hundreds of pdb files to modify).
Can someone help?
Both solutions below mess up the formatting of my pdb file, meaning I get:
HETATM 1 PA FAD B 600 95.887 47.194 74.387 1.00 -73.248
instead of
HETATM 1 PA FAD B 600 95.987 47.188 74.293 1.00 -73.248
am I doing something wrong or do you have any ideas why that is?
,
is that the issue? Why don't you just runawk '{$11="-81.88"}1' File1
?-81.883
from the first line's third column of file 2 but doesn't know how to glue that extract into the replacement code.