Как насчет этого.... однозначно кувалдой.
Вызовите его как thisScript Prob01.txt 0.75 0.25
, чтобы применить комбинации +/ -75% изменения для 1-го и +/ -25% для 3-го значения для каждой реакции и записать их в отдельные файлы
#!/bin/bash
#takes $inputFile $pct1 $pct3
#note $pct is the multiplier expressed as a decimal
#global variables
#$w : the line number and original figures, space separated
#$newFile : the new file name
#$o : the original figures in the original format
#$n : the new figures in the correct format
inputFile=$1
#strip the suffix (.txt) from the inputFile name
outFile=${inputFile%.*}
pct1=$2
pct3=$3
function domath {
# takes $value $multiplier
local m=$(echo 1+$2 | bc -l)
local theanswer=$(echo $1 $m | awk '{printf "%7.6E\n", $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)
#retrieve the old string
o=$(echo $figures | grep -Po "(?<= ).*")
#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]} $pct1) ${w[2]} ${w[3]}")
;;
2)
n=$(echo "$(domath ${w[1]} -$pct1) ${w[2]} ${w[3]}")
;;
3)
n=$(echo "${w[1]} ${w[2]} $(domath ${w[3]} $pct3)")
;;
4)
n=$(echo "${w[1]} ${w[2]} $(domath ${w[3]} -$pct3)")
;;
esac
#make the changes
makechange $reaction $j
done
done
#clean up
rm step{A..B}
Ошибка не в more, а в libmagic
, что также используется file
.
Например, libmagic
сообщает, что пустой файл является двоичным, а more
имеет специальный код для обработки этого.
Я вижу по крайней мере два решения: вы можете собрать more
из исходников без поддержки libmagic или можете перейти на более раннюю версию libmagic
.
Кстати, вы должны сообщить об этом.