Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. r=""
  4. res=""
  5. while read line; do
  6. if [[ "$line" =~ ^(r[0-9]+f:[^ t]+)[[:space:]]+!+.+$ ]]; then
  7. r="${BASH_REMATCH[1]}"
  8. fi
  9. if [[ "$line" =~ ^(+[0-9]+..+[0-9])[[:space:]]+!+.+$ ]]; then
  10. res="${BASH_REMATCH[1]}"
  11. fi
  12. if [[ -n "$r" ]] && [[ -n "$res" ]]; then
  13. echo -e "$rtt$res"
  14. r=""
  15. res=""
  16. fi
  17. done < <(grep -E "^r[0-9]+f:|^+[0-9]+." /path/to/yourfile)
  18.  
  19. :/tmp$ bash script
  20. r1f:O2+2PD=>2O-PD +7.000000E-02 +0.000000E00 +0.000000E00
  21. r2f:C3H6+2PD=>C3H6-PD +9.800000E-01 +0.000000E00 +0.000000E00
  22. r3f:C3H6+O-PD+PD=>C3H5-PD+OH-PD +2.747319E-01 +0.000000E00 +0.000000E00
  23. r4f:H2+2PD=>2H-PD +4.600000E-02 +0.000000E00 +0.000000E00
  24. r5f:H2O+PD=>H2O-PD +2.492452E-01 +0.000000E00 +0.000000E00
  25. r6f:CO2+PD=>CO2-PD +5.000000E-03 +0.000000E00 +0.000000E00
  26.  
  27. #!/bin/bash
  28.  
  29. while read line; do
  30. if [[ "$line" =~ ^(r[0-9]+f:[^ t]+)[[:space:]]+!+.+$ ]]; then
  31. r="${BASH_REMATCH[1]}"
  32. fi
  33. if [[ "$line" =~ ^(+[0-9.Ee-]+)[[:space:]]+(+[0-9.Ee-]+)[[:space:]]+(+[0-9.Ee-]+)[[:space:]]+!+.+$ ]]; then
  34. res1="${BASH_REMATCH[1]}"
  35. res2="${BASH_REMATCH[2]}"
  36. res3="${BASH_REMATCH[3]}"
  37. res1=$(echo $res1 | awk '{ printf "%.6E",$1*1.75 }')
  38. res3=$(echo $res3 | awk '{ printf "%.6E",$1*1.75 }')
  39. fi
  40. if [[ -n "$r" ]] && [[ -n "$res1" ]] && [[ -n "$res2" ]] && [[ -n "$res3" ]]; then
  41. echo -e "$rtt+$res1tt$res2tt+$res3"
  42. r=""
  43. res1=""
  44. res2=""
  45. res3=""
  46. fi
  47. done < <(grep -E "^r[0-9]+f:|^+[0-9]+." /path/to/yourfiles)
  48.  
  49. :/tmp$ bash script
  50. r1f:O2+2PD=>2O-PD +1.225000E-01 +0.000000E00 +0.000000E+00
  51. r2f:C3H6+2PD=>C3H6-PD +1.715000E+00 +0.000000E00 +0.000000E+00
  52. r3f:C3H6+O-PD+PD=>C3H5-PD+OH-PD +4.807808E-01 +0.000000E00 +0.000000E+00
  53. r4f:H2+2PD=>2H-PD +8.050000E-02 +0.000000E00 +0.000000E+00
  54. r5f:H2O+PD=>H2O-PD +4.361791E-01 +0.000000E00 +0.000000E+00
  55. r6f:CO2+PD=>CO2-PD +8.750000E-03 +0.000000E00 +0.000000E+00
  56.  
  57. #!/bin/bash
  58. #takes $inputFile $pct
  59. #note $pct is the multiplier expressed as a decimal
  60.  
  61. #global variables
  62. #$w
  63. #$newFile
  64. inputFile=$1
  65. #strip the suffix (.txt) from the inputFile name
  66. outFile=${inputFile%.*}
  67. pct=$2
  68.  
  69. function domath {
  70. # takes $value $multiplier
  71. local m=$(echo 1+$2 | bc -l)
  72. local theanswer=$(echo $1 $m | awk '{printf "%7.6En" , $1*$2}' | sed -E -e 's/[Ee]+*/E/g' -e 's/^([^-])/+1/g')
  73. echo $theanswer
  74. }
  75.  
  76. function makechange {
  77. #takes $reaction $case
  78. #compose new file name
  79. newFile=${outFile}_$1_$(printf "%02g" $2).txt
  80. #make a copy
  81. cp $inputFile $newFile
  82. #change the appropriate line
  83. sed -i "${w[0]}s/$o/$n/" $newFile
  84. }
  85.  
  86. #get all the reaction names
  87. grep -Po "^r[0-9]+f(?=:)" Prob01.txt > stepA
  88.  
  89. #get all the figures and their line numbers in case duplicates occur
  90. grep -Pon "^+[^!]*" Prob01.txt > stepB
  91.  
  92. for ((i=1; i<=$(cat stepA | wc -l); i++)); do
  93. reaction=$(sed "${i}q;d" stepA)
  94. figures=$(sed "${i}q;d" stepB | sed 's/:/ /g')
  95. w=($figures)
  96. #recompose the old string with double spaces as it was
  97. o=$(echo "${w[1]} ${w[2]} ${w[3]}")
  98. #compose the new string for each of the 4 cases
  99. for ((j=1; j<=4; j++)); do
  100. case $j in
  101. 1)
  102. n=$(echo "$(domath ${w[1]} $pct) ${w[2]} ${w[3]}")
  103. ;;
  104. 2)
  105. n=$(echo "$(domath ${w[1]} -$pct) ${w[2]} ${w[3]}")
  106. ;;
  107. 3)
  108. n=$(echo "${w[1]} ${w[2]} $(domath ${w[3]} $pct)")
  109. ;;
  110. 4)
  111. n=$(echo "${w[1]} ${w[2]} $(domath ${w[3]} -$pct)")
  112. ;;
  113. esac
  114. #make the changes
  115. makechange $reaction $j
  116. done
  117.  
  118. done
  119. #clean up
  120. rm step{A..B}
  121.  
  122. thisScript Prob.txt 0.75
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement