Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- r=""
- res=""
- while read line; do
- if [[ "$line" =~ ^(r[0-9]+f:[^ t]+)[[:space:]]+!+.+$ ]]; then
- r="${BASH_REMATCH[1]}"
- fi
- if [[ "$line" =~ ^(+[0-9]+..+[0-9])[[:space:]]+!+.+$ ]]; then
- res="${BASH_REMATCH[1]}"
- fi
- if [[ -n "$r" ]] && [[ -n "$res" ]]; then
- echo -e "$rtt$res"
- r=""
- res=""
- fi
- done < <(grep -E "^r[0-9]+f:|^+[0-9]+." /path/to/yourfile)
- :/tmp$ bash script
- r1f:O2+2PD=>2O-PD +7.000000E-02 +0.000000E00 +0.000000E00
- r2f:C3H6+2PD=>C3H6-PD +9.800000E-01 +0.000000E00 +0.000000E00
- r3f:C3H6+O-PD+PD=>C3H5-PD+OH-PD +2.747319E-01 +0.000000E00 +0.000000E00
- r4f:H2+2PD=>2H-PD +4.600000E-02 +0.000000E00 +0.000000E00
- r5f:H2O+PD=>H2O-PD +2.492452E-01 +0.000000E00 +0.000000E00
- r6f:CO2+PD=>CO2-PD +5.000000E-03 +0.000000E00 +0.000000E00
- #!/bin/bash
- while read line; do
- if [[ "$line" =~ ^(r[0-9]+f:[^ t]+)[[:space:]]+!+.+$ ]]; then
- r="${BASH_REMATCH[1]}"
- fi
- if [[ "$line" =~ ^(+[0-9.Ee-]+)[[:space:]]+(+[0-9.Ee-]+)[[:space:]]+(+[0-9.Ee-]+)[[:space:]]+!+.+$ ]]; then
- res1="${BASH_REMATCH[1]}"
- res2="${BASH_REMATCH[2]}"
- res3="${BASH_REMATCH[3]}"
- res1=$(echo $res1 | awk '{ printf "%.6E",$1*1.75 }')
- res3=$(echo $res3 | awk '{ printf "%.6E",$1*1.75 }')
- fi
- if [[ -n "$r" ]] && [[ -n "$res1" ]] && [[ -n "$res2" ]] && [[ -n "$res3" ]]; then
- echo -e "$rtt+$res1tt$res2tt+$res3"
- r=""
- res1=""
- res2=""
- res3=""
- fi
- done < <(grep -E "^r[0-9]+f:|^+[0-9]+." /path/to/yourfiles)
- :/tmp$ bash script
- r1f:O2+2PD=>2O-PD +1.225000E-01 +0.000000E00 +0.000000E+00
- r2f:C3H6+2PD=>C3H6-PD +1.715000E+00 +0.000000E00 +0.000000E+00
- r3f:C3H6+O-PD+PD=>C3H5-PD+OH-PD +4.807808E-01 +0.000000E00 +0.000000E+00
- r4f:H2+2PD=>2H-PD +8.050000E-02 +0.000000E00 +0.000000E+00
- r5f:H2O+PD=>H2O-PD +4.361791E-01 +0.000000E00 +0.000000E+00
- r6f:CO2+PD=>CO2-PD +8.750000E-03 +0.000000E00 +0.000000E+00
- #!/bin/bash
- #takes $inputFile $pct
- #note $pct is the multiplier expressed as a decimal
- #global variables
- #$w
- #$newFile
- inputFile=$1
- #strip the suffix (.txt) from the inputFile name
- outFile=${inputFile%.*}
- pct=$2
- function domath {
- # takes $value $multiplier
- local m=$(echo 1+$2 | bc -l)
- local theanswer=$(echo $1 $m | awk '{printf "%7.6En" , $1*$2}' | sed -E -e 's/[Ee]+*/E/g' -e 's/^([^-])/+1/g')
- echo $theanswer
- }
- function makechange {
- #takes $reaction $case
- #compose new file name
- newFile=${outFile}_$1_$(printf "%02g" $2).txt
- #make a copy
- cp $inputFile $newFile
- #change the appropriate line
- sed -i "${w[0]}s/$o/$n/" $newFile
- }
- #get all the reaction names
- grep -Po "^r[0-9]+f(?=:)" Prob01.txt > stepA
- #get all the figures and their line numbers in case duplicates occur
- grep -Pon "^+[^!]*" Prob01.txt > stepB
- for ((i=1; i<=$(cat stepA | wc -l); i++)); do
- reaction=$(sed "${i}q;d" stepA)
- figures=$(sed "${i}q;d" stepB | sed 's/:/ /g')
- w=($figures)
- #recompose the old string with double spaces as it was
- o=$(echo "${w[1]} ${w[2]} ${w[3]}")
- #compose the new string for each of the 4 cases
- for ((j=1; j<=4; j++)); do
- case $j in
- 1)
- n=$(echo "$(domath ${w[1]} $pct) ${w[2]} ${w[3]}")
- ;;
- 2)
- n=$(echo "$(domath ${w[1]} -$pct) ${w[2]} ${w[3]}")
- ;;
- 3)
- n=$(echo "${w[1]} ${w[2]} $(domath ${w[3]} $pct)")
- ;;
- 4)
- n=$(echo "${w[1]} ${w[2]} $(domath ${w[3]} -$pct)")
- ;;
- esac
- #make the changes
- makechange $reaction $j
- done
- done
- #clean up
- rm step{A..B}
- thisScript Prob.txt 0.75
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement