sed - sed 找到带有集合文章的行 (a, an, the)
问题描述
我应该找到我自己设置的文章的行。在前 10 行中搜索。
sed -n '/the/p' file.txt | sed -n '/ a /p' file.txt
将仅显示最后一个命令的输出。还
sed -n '1,10 /the/p' file
或者
sed -n 1,10p '/the/p' file
不工作,我发现范围的使用只与像这样的模式
[range]/s/pattern/pattern/p
如何结合多个条件和行范围?
文件示例:
For the first time since early February
the top three films at the weekend
box office were all new releases
and leading the way was
Fox's Bohemian Rhapsody
with a $50 million
chart-topping performance
well above expectations.
That said, the weekend isn't all about
new releases as the holdovers
输出应该是:
For the first time since early February
the top three films at the weekend
and leading the way was
with a $50 million
That said, the weekend isn't all about
new releases as the holdovers
解决方案
获取包含的行
the
sed -n '1,10{/\<the\>/p}' file
获取包含
the
ora
或 or的行an
sed -n '1,10{/\<\(the\|a\|an\)\>/p}' file
推荐阅读
- python-3.x - 如何使用python读取自动发送到手机的OTP?
- android - 使用 base64 的 WebView 不加载图像
- vbscript - 是否可以从alm重命名下载的附件?
- postgresql - 将多个 csv.gz 格式导入 windows 上的 postgres 表
- python - 为什么我的 sigmoid 函数返回的值不在 ]0,1[ 区间内?
- docker - 昨天成功运行的 Docker 命令和设置今天开始在 Windows 10 上突然出现错误“ENOENT”
- javascript - 什么是在谷歌地图 API 中创建三角形坐标的理想方法,其中两个位置点由纬度和经度组成
- css - 使 thead 固定且 tbody 可滚动后,thead 和 tbody 未正确对齐
- amazon-web-services - 无法验证以下目标配置((服务:Amazon S3;状态代码:400;错误代码:InvalidArgument)
- javascript - 如何将属性从组件的 prop 方法传递给处理程序?