首页 > 解决方案 > 提取两个字符串之间的文本,但仅使用 sed 第一次出现?

问题描述

所以我有一个看起来像这样的字符串:

<tag>Hello world </tag> blah blah blah <tag> Good night !! </tag>

我只需要提取hello world。知道如何构建 sed 命令吗?

标签: shellsedsh

解决方案


使用简单的切割:

echo "<tag>Hello world </tag> blah blah blah <tag> Good night ls -ltrh cptrade* </tag>" | cut -d'>' -f2 | cut -d'<' -f1

推荐阅读