Linux运维工程师面试题大全09_文本处理三剑客之SED

版权声明:本文为博主原创文章,转载请声明出处! https://blog.csdn.net/weixin_42758707/article/details/90551103

答案就在下一行,鼠标选中就看到了
像这样
像这样
在这里插入图片描述在这里插入图片描述

Linux面试题

1、linux系统中,____命令可以从文本文件的每一行中截取指定的内容的数据。
cut

2、在每一行后增加一空行?
set ‘G’ test.txt

3、在匹配regex的行之后插入一空行?
sed ‘/regex/G’ text.txt

4、计算文件行数?
wc -l

5、sed将文件test中第50行中的haiwao改为haiwai?
sed ‘50s/haiwao/haiwai/’ test

6、替换一个文件/etc/passwd里的这root:x:0:0:root:/root:/bin/bash一行第二个root为test?
sed ‘/root/s/:root:/:test:/’ /etc/passwd

7、打印/etc/passwd的奇数行?
sed -n ‘1~2p’ /etc/passwd

8、⽇志⽂件a.log,内容是时间顺序递增,从0点到23点的所有⽇志记录,每条时间的⽇志为⼀⾏:
2016/06/12 00:00:00 - - 200 190 http://www.a.com/o1html xxxxxxx
2016/06/12 00:00:01 - - 200 390 http://www.b.com/o1html xxxxxxx
2016/06/12 00:00:02 - - 200 490 http://www.v.com/o.html xxxxxxx
2016/06/12 00:00:03 - - 200 890 http://www.a.com/o.html xxxxxxx

2016/06/12 23:59:56 - - 200 320 http://www.3.com/o.jpg xxxxxxx
2016/06/12 23:59:57 - - 200 131 http://www.9.com/o.html xxxxxxx
2016/06/12 23:59:58 - - 200 489 http://www.r.com/o.net xxxxxxx
2016/06/12 23:59:59 - - 200 772 http://www.w.com/o.php xxxxxxx
打印出05点到12点之间的所有日志?打印出05:30:35到22:45:55之间的所有日志?
sed -nr ‘/05:30:35/,/22:45:55/p’ file.log
或sed -nr ‘/05:[3-5][0-9]:(3[5-9]|[4-5][0-9])|(0[6-9]|1[0-9]|2[0-1]): ([0-5][0-9]): ([0-5][0-9])|22:
([0-3][0-9]|4[0-5]): ([0-4][0-9]|5[0-5])/p’ file.log

猜你喜欢

转载自blog.csdn.net/weixin_42758707/article/details/90551103
今日推荐