for f in *_200x200*; do
mv -- "$f" "${f/_200x200/}"
done
или если у вас есть команда perl rename
:
rename 's/_200x200//'./*_200x200*
С парой функций bash, paste
, bc
и csvtool
, вы можете легко добраться туда, если у вас есть файл для работы:
div() {
printf "%1.4f\n" $(bc -l <<<"1.0 * $1 / $2")
}
export -f div
ratio() {
echo "$1"_"$2"
csvtool -t ' ' namedcol $1,$2 data.ssv |
tail -n+2 |
csvtool call div -
}
paste -d ' ' <(cat data.ssv) <(ratio foo bar) <(ratio foo biz) <(ratio bar biz) |
csvtool -t ' ' readable -
Выход:
foo bar biz foo_bar foo_biz bar_biz
10 100 1000 0.1000 0.0100 0.1000
11 150 990 0.0733 0.0111 0.1515
10 95 1010 0.1053 0.0099 0.0941
9 99 950 0.0909 0.0095 0.1042
Если вы действительно хотите сделать это в потоковом режиме, лучшим вариантом, вероятно, будет awk
, например.:
parse.awk
# Parse the requested column ratios into dividend[] and divisor[]
# by column name
BEGIN {
split(ratios_str, ratios, / +/)
for(r in ratios) {
split(ratios[r], cols, /,/)
dividend[++i] = cols[1]
divisor[i] = cols[2]
}
}
# Sort out the header
NR == 1 {
# Create the ColumnName-to-ColumnNumber hash
split($0, a); for(k in a) c2n[a[k]]=k
# Print the header line
printf "%s ", $0
for(i=1; i<=length(dividend); i++)
printf "%s_%s ", dividend[i], divisor[i]
printf "\n"
}
NR > 1 {
printf "%s ", $0
for(i=1; i<=length(dividend); i++)
printf "%1.4f ", $(c2n[dividend[i]]) / $(c2n[divisor[i]])
printf "\n"
}
Запустите это так:
<data.ssv awk -f parse.awk -v ratios_str='foo,bar foo,biz bar,biz' | column -t
Выход:
foo bar biz foo_bar foo_biz bar_biz
10 100 1000 0.1000 0.0100 0.1000
11 150 990 0.0733 0.0111 0.1515
10 95 1010 0.1053 0.0099 0.0941
9 99 950 0.0909 0.0095 0.1042
Использование Миллера(https://github.com/johnkerl/miller)и запуск
mlr --pprint put '$foo_bar=$foo/$bar;$foo_biz=$foo/$biz;$bar_biz=$bar/$biz' input >output
у вас есть
foo bar biz foo_bar foo_biz bar_biz
10 100 1000 0.100000 0.010000 0.100000
11 150 990 0.073333 0.011111 0.151515
10 95 1010 0.105263 0.009901 0.094059
9 99 950 0.090909 0.009474 0.104211