如何使用grep从段落中提取句子

时间:2019-07-07 16:50:15

标签: regex grep

假设我有多段文字,以START和END开头和结尾。

示例:

              stationIds    years    GroupCount    mean_temp    min_temp    max_temp      meanci_temp       mean_rain    min_rain    max_rain      meanci_rain   
              __________    _____    __________    _________    ________    ________    ________________    _________    ________    ________    ________________

    1_2016    1             2016      82            63.13       30.008       99.22      58.543    67.717    6.1181       0           19.729      4.6284    7.6078
    1_2017    1             2017     365           65.914       30.028      99.813      63.783    68.045    5.0075       0           19.933      4.3441    5.6708
    1_2018    1             2018     365           65.322       30.218      99.773      63.275    67.369    4.7039       0           19.884      4.0615    5.3462
    1_2019    1             2019     188           63.642        31.16      99.654      60.835    66.449    5.9186       0           19.864      4.9834    6.8538
    2_2016    2             2016      82           65.821       31.078      98.144      61.179    70.463    4.7633       0           19.688      3.4369    6.0898
    2_2017    2             2017     365           66.002       30.054      99.896      63.902    68.102    4.5902       0           19.902      3.9267    5.2537
    2_2018    2             2018     365           66.524       30.072      99.852      64.359     68.69    4.9649       0           19.812      4.2967    5.6331
    2_2019    2             2019     188           66.481       30.249      99.889      63.647    69.315    5.2711       0           19.811      4.3234    6.2189
    3_2016    3             2016      82           61.996       32.067      98.802      57.831    66.161    4.5445       0           19.898      3.1523    5.9366
    3_2017    3             2017     365           63.914       30.176      99.902      61.932    65.896    4.8879       0           19.934       4.246    5.5298
    3_2018    3             2018     365           63.653       30.137      99.991      61.595    65.712    5.3728       0           19.909      4.6943    6.0514
    3_2019    3             2019     188           64.201       30.078        99.8      61.319    67.082    5.3926       0           19.874      4.4541    6.3312

如何使用grep从每个段落的START和END单词中提取内容并存储在数组中。

预先感谢您的帮助

1 个答案:

答案 0 :(得分:1)

也许您能从中得到一些想法:

模式:(?<= START)(。*)(?= END)

**Match 1**
1.  i am just and example of a multiline paragraph having some unique informations in each para. I end with a capital
**Match 2**
1.  i am just and example of a multiline paragraph having some unique informations in each para. You see in this paragraph I have one extra line.I end with a capital

https://rubular.com/r/BwL7Wq6vaZdWaC

相关问题