Reading multiple values from multiple lines and columns and setting them to unique variables.

Hello,

I would like to ask for help with csh script.

An example of an input in .txt file is below, the number of lines varies from file to file and I have 2 or 3 columns with values. I would like to read all the values (probably one by one) and set them to independent unique variables that can be used later for mathematical operations or "cat" outputs. Is it possible to do it in C-shell? I would not like to change the shell because I want to add this part to my "value extraction" script which I made.

Thanks for the help.

125 143 19
149 153  5
216 224  9
226 247 22
250 254  5
255 275 21
290 292  3
296 302  7
306 323 18
326 339 14
348 371 24
378 406 29
410 414  5
415 423  9

Welcome to forums, please describe your query clearly, how do you expect output ? can we have sample output for example input you have posted.

Thanks for the message. I am sorry I thought it was clear enough. Actually I am not expecting any output just assiging the values to variables (if that is what you meant):

"variable n1" = 125
"variable n2" = 143
"variable n3" = 19
etc

Then I want to use these variables in specific format to write to .txt file which will be used as an input for further calculations by other program.

if you describe the 'specific format' AND what the 'further calculations' are maybe you don't need 'variables' (most likely not) and everything (including the calculations) can be done in one step.

OK I did not want to go to much into details... So I want to use whose variables to write to the new text file e.g. out_PyMOL_angles_{$pdbid}.txt (which will be actually a PyMOL script to calculate structural properties in the protein e.g. angle between two helices) such as:

cat > out_PyMOL_angles_{$pdbid}.txt << EOF -- $pdbid has been defined already

# Output for generating helix assignement in $pdbid.txt
async=0
select HELIX1, /$pdbid//$ChainId/$variable n1 - $variable n2/ -- where $variable n1 is 125 and $variable n2 is 143 (first line column 1 and column 2)
select HELIX2, /$pdbid//$ChainId/$variable n4 - $variable n5/ -- where $variable n4 is 149 and $variable n5 is 153 (second line column 1 and column 2)
angle_between_helices HELIX1, HELIX2

EOF

But with the above part I am fine.

I just need to set/assign all the values from the original .txt file into unique variables:

125 143 19
149 153  5
216 224  9
226 247 22
250 254  5
255 275 21
290 292  3
296 302  7
306 323 18
326 339 14
348 371 24
378 406 29
410 414  5
415 423  9

something along these line?:

 awk '{printf("select HELIX%d, /$pdbid//$ChainId/%d - %d/\n", FNR, $1,$2)}' myFile

Unless you want do the actual substruction of numbers?

 awk '{printf("select HELIX%d, /$pdbid//$ChainId/%d/\n", FNR, $1-$2)}' myFile
1 Like

Wow using the first option I have got the exact thing I wanted. Thank you very much:

select HELIX1, /1DB1//A/125 - 143/
select HELIX2, /1DB1//A/149 - 153/
select HELIX3, /1DB1//A/216 - 224/
select HELIX4, /1DB1//A/226 - 247/
select HELIX5, /1DB1//A/250 - 254/
select HELIX6, /1DB1//A/255 - 275/
select HELIX7, /1DB1//A/290 - 292/
select HELIX8, /1DB1//A/296 - 302/
select HELIX9, /1DB1//A/306 - 323/
select HELIX10, /1DB1//A/326 - 339/
select HELIX11, /1DB1//A/348 - 371/
select HELIX12, /1DB1//A/378 - 406/
select HELIX13, /1DB1//A/410 - 414/
select HELIX14, /1DB1//A/415 - 423/

there was only a small modification needed to get the $pdbid and $ChainId values correctly.

 awk '{printf("select HELIX%d, /'$pdbid'//'$ChainId'/%d - %d/\n", FNR, $1,$2)}' myFile

a better approach:

awk '{printf("select HELIX%d, /%s//%s/%d - %d/\n", FNR, ,pd,chid,$1,$2)}' pd="${pdbid}" chid="${ChainId}" myFile