从非常长的字符串unix中获取特定数据

时间:2013-10-25 13:29:32

标签: string 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

的变量中

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

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

scorex: (\d+)

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

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

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

 34
 687
 9
相关问题