I am trying to substitute coordinates of a particular line in one file for the coordinates of a different file. Both of them have a line in them that has "code word" in them and that is where the coordinates are found. The ccordinates are also on the same sets of columns, 33-54, if that helps. How can I label a certain part of the line of interest as a variable so I could use sed to substitute? This is what I have so far:
#!/bin/bash
FILE=$1
grep -i "ABC DEF" $FILE.pdb
# Somehow select the coordinates in the line with "ABC DEF" in $FILE.pdb and label it PDBcoords
PDBcoords=$unknownfunction1
$Somehow select the coordinates in the line with "ABC DEF" in reference.pdb and label it refcoords
grep -i "ABC DEF" reference.pdb
refcoords=$unknownfunction2
sed -i 's/$refcoords/$PDBcoords/'
wait
echo "Whole Command Done for $FILE"
The grep outputs looks like this:
ATOM 5103 ABC DEF A 100 5.817 2.502 -21.483 1.00 13.63 O
and I only want to select the coordinates
5.817 2.502 -21.483
However, these coordinates change for every file, so I need to label these columns as a variable. Same goes for the reference pdb.
EDIT I came up with this solution:
#!/bin/bash
FILE=$1
PDB=$(grep -i "OXT ORN" $FILE.pdb | cut -c 33-54)
PDBcoords="$(echo "$PDB")"
echo $PDBcoords
echo Found PDB Coordinates for $FILE
pkaSH=$(grep -i "OXT ORN" pkaSH.pdb | cut -c 33-54)
pkaSHcoords="$(echo "$pkaSH")"
echo $pkaSHcoords
echo Found pkaSH Coordinates for $FILE
sed -i "s/$pkaSHcoords/$PDBcoords/" pkaSH.pdb
echo Command Done
My idea was to redirect the grep output to a temporary file, cut out the coordinate columns, and then define that as a variable with spaces preserved. I'm sure this was overcomplicated, but since it works I think I have my answer.