This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Bash script error on reading coordinates in a file

Hi guys, Within last few hours I had a problem with extracting coordinates from pdb files in a batch mode with my script. Anyone can suggest me a tricky way to skip that?

my script :

#!/bin/bash
 while read line
 do
 echo $line
  iden=echo $line | awk -F "," {'print $1'}
  pos=echo $line | awk -F "," {'print $2'}
  echo $iden
  file=$iden".pdb"
  x=cat $file | tr 'A' ' ' | awk '/ATOM/ && $3 == "CA" && $4 == "GLU" && $5 == $pos {print $6}'
  y=cat $file | tr 'A' ' ' | awk '/ATOM/ && $3 == "CA" && $4 == "GLU" && $5 == $pos {print $7}'
  z=cat $file | tr 'A' ' ' | awk '/ATOM/ && $3 == "CA" && $4 == "GLU" && $5 == $pos {print $8}'
  echo $iden","$x","$y","$z",," >> loci.csv;
 done < "locations.txt"

and the response in cygwin is :

location.sh: line 6: A0A010PSQ8,182: command not found
location.sh: line 7: A0A010PSQ8,182: command not found

location.sh: line 10: .pdb: command not found
location.sh: line 11: .pdb: command not found
location.sh: line 12: .pdb: command not found

my locations.txt file :

A0A010PSQ8,182

...

Can anybody help me please? I really appreciate an answer that can help me fast

pdb bash text-processing

1 answer

not

 iden=echo $line | awk -F "," {'print $1'}

but

 iden=`echo $line | awk -F "," {'print $1'}`

(backquote)

Thanks a lot for your guidance :) it resolved the first lines of getting identifier and 'pos' but in getting x,y,z coordinates again this error occured :

location.sh: line 9: A0A061QH30.pdb: command not found
location.sh: line 10: A0A061QH30.pdb: command not found
location.sh: line 11: A0A061QH30.pdb: command not found

and i guess this was about not getting the awk command informations. thanks again

As you can see it is the same error, try to put your code line between `` like:

`cat $file | tr 'A' ' ' | awk '/ATOM/ && $3 == "CA" && $4 == "GLU" && $5 == $pos {print $6}'`

The backtick (``) is actually called command substitution. The purpose of command substitution is to evaluate the command which is placed inside the backtick and provide its result as an argument to the actual command.

alternatively you can use $()

Log in to answer this question.