如何打印位置

如何打印位置

如何使用数组编写以下行?

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

相关内容