如何在shell中提取两个单词之间的值



我有一个这样的字符串:line="06:13:41.817 INFO ProgressMeter - Traversal complete. Processed 46942 total variants in 2.2 minutes."

我想提取46942并放入一个变量。

我试过这个,但它只删除了Processed和total。我该怎么做?

Var=$(echo $line | sed -e 's/Processed(.*)total/1/')

使用参数扩展:

line="06:13:41.817 INFO ProgressMeter - Traversal complete. Processed 46942 total variants in 2.2 minutes."
line=${line#*'Processed '}  # Remove from left up to "Processed ".
line=${line%' total'*}      # Remove from from " total" up to the end.

相关内容

  • 没有找到相关文章

最新更新