我有一个这样的字符串: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.