gpt4 book ai didi

search - Grep 查找字符串并读取内容直到下一个匹配字符串

转载 作者:行者123 更新时间:2023-12-02 03:32:31 25 4
gpt4 key购买 nike

我正在尝试读取文件并使用 grep 搜索字符串。一旦找到该字符串,我想读取该字符串之后的所有内容,直到匹配另一个字符串。因此,在我的示例中,我正在搜索 ...SUMMARY... 并且我想读取所有内容,直到出现 ... 这是一个示例:

**...SUMMARY...**
Severe thunderstorms are most likely across north-central/northeast
Texas and the Ark-La-Tex region during the late afternoon and
evening. Destructive hail and wind, along with a few tornadoes are
possible. Severe thunderstorms are also expected across the
Mid-South and Ohio Valley.

**...**North-central/northeast TX and southeast OK/ArkLaTex...
In the wake of a decaying MCS across the Lower Mississippi River
Valley, a northwestward-extending outflow boundary will continue to
modify/drift northward with rapid/strong destabilization this
afternoon particularly along and south of it. A quick
reestablishment of lower/some middle 70s F surface dewpoints will
occur into prior-MCS-impacted areas, with MLCAPE in excess of 4000
J/kg expected for parts of north-central/northeast Texas into far
southeast Oklahoma and the nearby ArkLaTex. Special 19Z observed
soundings are expected from Fort Worth/Shreveport to help better
gauge/confirm this destabilization trend and the degree of capping.

我尝试使用以下代码,但仅显示 ...SUMMARY... 和下一行。

sed -n '/...SUMMARY.../,/.../p' 

我该如何解决这个问题?

================================================== =======================后续:

这就是我想要得到的结果。只显示...摘要...下的段落,并在下一个结束...所以这就是我最终应该得到的:

中北部/东北部地区最有可能出现强雷暴 德克萨斯州和阿克-拉-德克萨斯地区下午晚些时候和 晚上。破坏性的冰雹和大风,以及一些 Tornado 可能的。预计全境还将出现强雷暴天气 中南部和俄亥俄河谷。

我根据 Shellter 的建议尝试了以下操作:

sed -n '/...摘要.../,/**...**/p'

但我得到了一切。

最佳答案

您可以使用

sed -n '/^[[:blank:]]*\.\.\.SUMMARY\.\.\./,/^[[:blank:]]*\.\.\./{//!p;}' file

参见this online sed demo .

注释:

关于search - Grep 查找字符串并读取内容直到下一个匹配字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56673223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com