![如何打印位置](https://linux22.com/image/186966/%E5%A6%82%E4%BD%95%E6%89%93%E5%8D%B0%E4%BD%8D%E7%BD%AE.png)
如何使用数组编写以下行?
val1=$(grep 'Thread' Threadout.txt | awk -F"/" '{print $1}')
val2=$(grep 'Thread' Threadout.txt | awk -F"/" '{print $2}')
val3=$(grep 'Thread' Threadout.txt | awk -F"/" '{print $3}')
val4=$(grep 'Thread' Threadout.txt | awk -F"/" '{print $4}')
Threadout.txt 包含“Thread 1/1/25/100”
答案1
使用以下命令创建数组readarray
:
readarray -t val < <(grep -o '[0-9]*' Threadout.txt)
然后你可以使用数组val
:
for v in "${val[@]}"; do
echo "$v"
done
或者
for k in "${!val[@]}"; do
echo "${val[$k]}"
done
输出:
1
1
25
100