Thu Feb 19 10:42:50: Submitted from host <iitmlogin5-ib0>, CWD <$HOME/Bipin/JAS_Data/Big_Domain/128np_IC/Normal_queue>, Output File <file.stdout.159375>, Error File <file.stderr.159375>, Exclusive Execution, 128 Task(s), Requested Resources <span[ptile=16]>; RUNLIMIT
从上面给定的行中,我想提取任务的值,即“128”和“16”ptile。想要读取变量中的值
任务 = 128 ptile = 16
最佳答案
您可以将grep -P
与read
一起使用:
read task ptile < <(grep -oP '.*\K\b\d+(?= Task)|.*ptile=\K\d+' file | tr '\n' ' ')
echo "[$task] - [$ptile]"
[128] - [16]
关于bash - 提取值并读取为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28778794/