我正在尝试从中提取值(value)
在 File.txt 中:
116206K->13056K(118080K), 0.0879950 secs][Tenured:274796K->68056K(274892K), 0.2713740 secs] 377579K->68056K(392972K), [Perm :17698K->17604K(17920K)], 0.3604630 secs]
我尝试提取
cat File.txt | grep 'Perm '| cut -d',' -f3|cut -d'(' -f2 |cut -d')' -f 1
这里有什么问题。因为我正在尝试我得到了
392972K 从 377579K->68056K(392972K)
但我应该从 [Perm :17698K->17604K(17920K)] 17920
最佳答案
一个快速修复,将 -f3
更改为 -f4
,因为您需要的字段出现在 之后 第 3 个逗号:
cat File.txt | grep 'Perm '| cut -d',' -f4|cut -d'(' -f2 |cut -d')' -f 1
^^
您还可以将 sed
用作:
grep 'Perm' File.txt | sed -r 's/.*Perm :.*\((.*?)\).*/\1/'
关于linux - grep 命令不能正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3996090/