Ricardo

SED 查询文本与行号

阅读时长: 1 分钟

#linux #command #sed

sed 打印匹配内容

代码
1
2
3
4
5
6
# sed -n -e '/build/p' filename
[cli_rebuild]

p -打印行
n -
e --e<script>或--expression=<script>:以选项中的指定的script来处理输入的文本文件;

sed 打印匹配内容行号

代码
1
sed -n -e '/build/=' filename

sed 打印匹配内容和行号

代码
1
2
3
# sed -n -e '/build/p' -e '/build/=' filename
[cli_rebuild]
28

打印文件中间几行,显示 5-10 行中间的内容

Shell
1
2
sed -n "3p" filename
sed -n '5,10p' filename

打印文件某一行到最后一行

Shell
1
sed -n '5,$p' filename

某个时间段日志,2020-07-17T18:15:52 日志中的时间格式,并且存在该时间

Shell
1
sed -n "/2020-07-17T18:15:52/,/2020-07-17T22:52:45/p" filename
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
记录自己
Built with Hugo
主题 Stack 由 Jimmy 设计