⽂本处理三剑客之SED面试题

一级标题

⽂本处理三剑客之SED面试题

1、linux系统中,__cut__命令可以从⽂本⽂件的每⼀⾏中截取指定的内容的数据。

2、在每⼀⾏后增加⼀空⾏?
[root@magedu ~]# sed 'G' text.txt

3、在匹配regex的⾏之后插⼊⼀空⾏?
[root@magedu ~]# sed '/regex/G' text.txt

4、计算⽂件⾏数?
cat 1.sh|wc -l

6、sed将⽂件test中第50⾏中的haiwao改为haiwai?
[root@magedu ~]# sed -n '50s/haiwao/haiwei/p' test

7、替换一个文件/etc/passwd里的这root❌0:0:root:/root:/bin/bash一行第二个root为test?
cat /etc/passwd| sed '/^root/!d'|sed 's/root/test/2'

8、打印/etc/passwd的奇数⾏?
[root@magedu ~]# sed -n '1~2p' /etc/passwd

9、⽇志⽂件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 -n '/2016/06/12 05:00:00/,/2016/06/12 12:00:00/p' a.log
sed -n '/2016/06/12 05:30:35/,/2016/06/12 22:45:55/p' a.log

posted @ 2020-06-07 14:32  饕鬄。。  阅读(297)  评论(0)    收藏  举报