2

我在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 的变量中

4

2 回答 2

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
于 2013-10-25T13:35:27.420 回答
0

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

scorex: (\d+)

将此模式与 grep 一起使用将如下所示:

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

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

 34
 687
 9
于 2013-10-25T13:39:45.520 回答