2013-10-25 22 views
2

我在unix中获取特定数据的脚本,运行一个程序后它给出了一个非常大的字符串,例如:(仅仅是一个随机的例子)从一个非常长的字符串中获取特定数据unix

In this example, the null scorex: 34;hypothesis of "marginal homogeneity" would mean there was no effect of the treatment. From the above data, the McNemar scorex: 687;test statistic with Yates's continuity correction is scorex: 9; 

,我喜欢,只要找到字符串“scorex:”它给我的实际得分:34,687或9,在这个例子中。

谢谢

我忘了,我的字符串是一个名为RESULTADO

回答

0

您可以使用变量中grep

grep -oP 'scorex:\s?\K\d*' input 

<command> | grep -oP 'scorex:\s?\K\d*' 

对于示例:

$ echo "In this example, the null scorex: 34;hypothesis of "marginal homogeneity" would mean there was no effect of the treatment. From the above data, the McNemar scorex: 687;test statistic with Yates's continuity correction is scorex: 9;" | grep -oP 'scorex:\s?\K\d*' 
34 
687 
9 
+0

你能送我我可以找到这个grep的选项如何工作的链接? (特别是\ s?\ K \ d *)。我是unix的新手,但我已经完成了一些教程,但没有人深入到grep。我想学习= D – Tamalero

0

这可以通过正则表达式来解决。考虑以下模式:

scorex: (\d+) 

使用此模式使用grep应该是这样的:

grep -Eo "scorex: (\d+)" file_containing_string | cut -d: -f2 

的这个输出是每个捕获结果:

34 
687 
9 
相关问题