Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我当前的代码:
for i in {0..5}; do rate[${i}]="`echo $line| awk -v par=$i '{par=par+2}{print $par}'`" done
从第二个开始提取每个字段并将其放入数组中。请告知是否有更优雅的方式来重写它。它不一定需要在 awk 中。
用于拆分输入并移位以set删除前两个元素:
set
set $line shift 2 rate=($@)
或shift按照 chepner 的建议消除:
shift
set $line rate=("${@:3}")
您可以使用变量替换运算符:
linetmp=${line#* } # remove up to the first space linetmp=${linetmp#* } remove up to the second (now first) space