how to get around lines to show and for analyze!!
2012-02-15 13:42
447 查看
[root@www ~]# grep [-A] [-B] [--color=auto] '搜尋字串' filename 選項與參數: -A :後面可加數字,為 after 的意思,除了列出該行外,後續的 n 行也列出來; -B :後面可加數字,為 befer 的意思,除了列出該行外,前面的 n 行也列出來; --color=auto 可將正確的那個擷取資料列出顏色 範例一:用 dmesg 列出核心訊息,再以 grep 找出內含 eth 那行 [root@www ~]# dmesg | grep 'eth' eth0: RealTek RTL8139 at 0xee846000, 00:90:cc:a6:34:84, IRQ 10 eth0: Identified 8139 chip type 'RTL-8139C' eth0: link up, 100Mbps, full-duplex, lpa 0xC5E1 eth0: no IPv6 routers present # dmesg 可列出核心產生的訊息!透過 grep 來擷取網路卡相關資訊 (eth) , # 就可發現如上資訊。不過沒有行號與特殊顏色顯示!看看下個範例吧! 範例二:承上題,要將捉到的關鍵字顯色,且加上行號來表示: [root@www ~]# dmesg | grep -n --color=auto 'eth' 247:eth0: RealTek RTL8139 at 0xee846000, 00:90:cc:a6:34:84, IRQ 10 248:eth0: Identified 8139 chip type 'RTL-8139C' 294:eth0: link up, 100Mbps, full-duplex, lpa 0xC5E1 305:eth0: no IPv6 routers present # 你會發現除了 eth 會有特殊顏色來表示之外,最前面還有行號喔! 範例三:承上題,在關鍵字所在行的前兩行與後三行也一起捉出來顯示 [root@www ~]# dmesg | grep -n -A3 -B2 --color=auto 'eth' 245-PCI: setting IRQ 10 as level-triggered 246-ACPI: PCI Interrupt 0000:00:0e.0[A] -> Link [LNKB] ... 247:eth0: RealTek RTL8139 at 0xee846000, 00:90:cc:a6:34:84, IRQ 10 248:eth0: Identified 8139 chip type 'RTL-8139C' 249-input: PC Speaker as /class/input/input2 250-ACPI: PCI Interrupt 0000:00:01.4[B] -> Link [LNKB] ... 251-hdb: ATAPI 48X DVD-ROM DVD-R-RAM CD-R/RW drive, 2048kB Cache, UDMA(66) # 如上所示,你會發現關鍵字 247 所在的前兩行及 248 後三行也都被顯示出來! # 這樣可以讓你將關鍵字前後資料捉出來進行分析啦! |
相关文章推荐
- How To determine DDIC Check Table, Domain and Get Table Field Text Data For Value?
- How To determine DDIC Check Table, Domain and Get Table Field Text Data For Value?
- How to get Intellisense for Web.config and App.config in Visual Studio .NET?(转载)
- How to Perform System Boot and Shutdown Procedures for Solaris 10, Part C
- How to get started with WebRTC and iOS without wasting 10 hours of your life
- Qt How to get the width and height of a widget
- How to reset password for Cisco router and switch
- How to stop looking for someone perfect and find someone to love
- how to get url and hostname and url text in one page
- How To Get Lync 2010 Call and Conversation History On Lync Mobile Device
- java - How to install and use db4o for Android? - Stack Overflow
- [笔记] How to get the versionCode and versionName of your app
- How to open and close wallet for Oracle Databse 11g?
- How to get Windows 8 Apps to use proxy for internet access
- Interpreting HANGANALYZE trace files to diagnose hanging and performance problems for 9i and 10g. (文
- How to read and understand a scientific paper: a guide for non-scientists
- How to fix hung_task_timeout_secs and blocked for more than 120 seconds problem
- Q: How to generate exe install and uninstall file for an eclipse product?
- How to add a user and set environments for the us
- How to Perform System Boot and Shutdown Procedures for Solaris 10, Part D