提取值并读取为变量

时间:2015-02-28 06:13:27

标签: bash awk sed scripting

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

从上面给出的行,我想提取任务的值No,即&#39; 128&#39;和&#39; 16&#39; ptile。想要在变量中读取这个值

任务= 128 ptile = 16

1 个答案:

答案 0 :(得分:2)

您可以将grep -Pread

一起使用
read task ptile < <(grep -oP '.*\K\b\d+(?= Task)|.*ptile=\K\d+' file | tr '\n' ' ')

echo "[$task] - [$ptile]"
[128] - [16]