shell scripting
From the given input file i want the output (shown below) which is the values of statements starting with Haripin loop and Muti-loop in each structure with its dG no. In input file they are shown in bold case. (original input file is a big one consists of n structures with n statements in this form only)HELP FOR SHELL SCRIPTING IS APPRECIATED. THANKS IN ADVANCE.
Something approaching: #!/bin/bash
PrintVal() { C=${C#(}; C=${C%)}; echo $C | sed 's/).*( /-/'; }
INFILE= # Put here the name of your file
while IFS=':=' read A B C
do
case "$A" in
"Initial dG ")
echo -e "\n\n$B\n"
Hairpins=0
;;
"Hairpin loop")
((Hairpins==0)) && echo "$A:"
PrintVal
((Hairpins++))
;;
"Multi-loop")
echo "$A:"
PrintVal
;;
esac
done <$INFILE
Result:
I modified as u suggested but it giving error like this
t2prog: line 21: syntax error near unexpected token `('
t2prog: line 21: ` done <($INFILE)'
Modified program is given here
#!/bin/bash
PrintVal() { C=${C#*(}; C=${C%)*}; echo $C | sed 's/).*( /-/'; }
INFILE= sai
while IFS=':=' read A B C
do
case "$A" in
"Initial dG ")
echo -e "\n\n$B\n"
Hairpins=0
;;
"Hairpin loop")
((Hairpins==0)) && echo "$A:"
PrintVal
((Hairpins++))
;;
"Multi-loop")
echo "$A:"
PrintVal
;;
esac
done <($INFILE)
---------- Post updated at 04:48 PM ---------- Previous update was at 03:55 PM ----------
The code is working (given below) and executed with original data. A small correction is required. In origianl data file the dG number statement will be generated like this
b Initial dG = -25.10 (i.e. one space from the beginning of the statement; so it is not coming on the output. The input cant change because it is automatically generated. In program make modification to print dG number if it is starting after one space from the beginning. If this statement is from the beginning of the line, the dG value is printing)
In the output, after printing each sequence '-e' is printing. that has to be removed (shown below)
The modified code is like this
--------------------------------
#!/bin/bash
PrintVal() { C=${C#*(}; C=${C%)*}; echo $C | sed 's/).*( /-/'; }
while IFS=':=' read A B C
do
case "$A" in
"Initial dG ")
echo -e "\n\n$B\n"
Hairpins=0
;;
"Hairpin loop")
((Hairpins==0)) && echo "$A:"
PrintVal
((Hairpins++))
;;
"Multi-loop")
echo "$A:"
PrintVal
;;
esac
done < sai
----------------------------------------
Output after run the program (original data output partial)
This means the output of program $INFILE is presented as a file. Using backticks instead means the output of program $INFILE is presented as a variable.
Correct would be:
done < "$INFILE"
---------- Post updated at 01:42 ---------- Previous update was at 01:39 ----------
You have a space between INFILE= and sai. There should be no space there.
I made corrections in the program as you suggested. It giving the output like this; It is not printing the dg number for all structures and Hairpin loop heading from the second structure.
I made corrections in the program as you suggested. It giving the output like this; It is not printing the dg number for all structures and Hairpin loop heading from the second structure.
I made modification as 'case $(echo $A) in' in script. Output is ok except '-e'. -e has to be removed. It is coming before every dG number i.e., -25.40, -25.10, etc. How it is coming I am in confusion. Thanks in advance.
Try this Posix version, which should be insensitive to leading spaces: INFILE=infile # Put the name of your file here
while read line
do
case $line in
"Initial dG")
printf "\n${line## }\n\n"
hairpins=false
;;
"Hairpin loop")
if ! $hairpins; then
printf "Hairpin loop: \n"
fi
( IFS="()"; set -- $line ; echo "${2# } ${4# }" )
hairpins=true
;;
"Multi-loop")
printf "Multi-loop: \n"
( IFS="()"; set -- $line ; echo "${2# } ${4# }" )
;;
esac
done <"$INFILE"