我正在尝试用逗号分隔的 13 个字段替换字符串中的字段。我既有要替换的位置,也有要在分隔变量中赋予该位置的新值。使用 bash。
#Original string:
THR=’0,0,0,0,0,0,0,0,0,0,0,0,0’
#Position I want to manipulate:
pos=’3’
#Value I want to write in the field "pos"
val=’8.73’
# What I'm trying to do:
echo $THR | awk -v chawk=$pos -v thrawk=$val -F',' '{ print; $chawk=$thrawk; print }'
THR 应该是 '0,0,8.73,0,0,0,0,0,0,0,0,0,0'
干杯