答案就在下一行,鼠標選中就看到了
像這樣
像這樣
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