리눅스 grep 범위 보기

grep 구간 보기
grep 범위 보기

1 이전 행 포함 (Before)[ | ]

grep -B행수 검색어
[root@zetawiki ~]# cat /var/log/messages | grep -B2 warn
Dec 18 23:41:16 localhost NetworkManager[1744]: (nm-device.c:4016):nm_device_queue_state: runtime check failed: (priv->queued_state.id == 0)
Dec 18 23:41:16 localhost NetworkManager[1744]: <info> modem-manager is now available
Dec 18 23:41:16 localhost NetworkManager[1744]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
--
Dec 19 09:04:48 localhost NetworkManager[1768]: (nm-device.c:4016):nm_device_queue_state: runtime check failed: (priv->queued_state.id == 0)
Dec 19 09:04:48 localhost NetworkManager[1768]: <info> modem-manager is now available
Dec 19 09:04:48 localhost NetworkManager[1768]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files

2 다음 행 포함 (After)[ | ]

grep -A행수 검색어
[root@zetawiki ~]# cat /var/log/messages | grep -A2 warn
Dec 18 23:41:16 localhost NetworkManager[1744]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
Dec 18 23:41:16 localhost NetworkManager[1744]: <info> Trying to start the supplicant...
Dec 18 23:41:16 localhost NetworkManager[1744]: <info> (eth1): device state change: 2 -> 3 (reason 40)
--
Dec 19 09:04:48 localhost NetworkManager[1768]: <warn> bluez error getting default adapter: The name org.bluez was not provided by any .service files
Dec 19 09:04:48 localhost NetworkManager[1768]: <info> Trying to start the supplicant...
Dec 19 09:04:48 localhost NetworkManager[1768]: <info> (eth1): device state change: 2 -> 3 (reason 40)

3 첫번째~마지막[ | ]

  • grep으로 행번호 확인하고, sed로 다시 조회해야 함
[root@zetawiki ~]# dmesg | grep ^e1000 -n
1549:e1000: Intel(R) PRO/1000 Network Driver - version 7.3.21-k8-NAPI
1550:e1000: Copyright (c) 1999-2006 Intel Corporation.
1553:e1000 0000:02:01.0: PCI INT A -> GSI 19 (level, low) -> IRQ 19
1554:e1000 0000:02:01.0: setting latency timer to 64
1555:e1000 0000:02:01.0: eth0: (PCI:66MHz:32-bit) 00:0c:29:a2:8e:a8
1556:e1000 0000:02:01.0: eth0: Intel(R) PRO/1000 Network Connection
1566:e1000: eth1 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
→ 'e1000'으로 시작하는 행들(1549 ~ 1566행 중 7개 행)
[root@zetawiki ~]# dmesg | sed '1549,1566!d'
e1000: Intel(R) PRO/1000 Network Driver - version 7.3.21-k8-NAPI
e1000: Copyright (c) 1999-2006 Intel Corporation.
  alloc irq_desc for 19 on node -1
  alloc kstat_irqs on node -1
e1000 0000:02:01.0: PCI INT A -> GSI 19 (level, low) -> IRQ 19
e1000 0000:02:01.0: setting latency timer to 64
e1000 0000:02:01.0: eth0: (PCI:66MHz:32-bit) 00:0c:29:a2:8e:a8
e1000 0000:02:01.0: eth0: Intel(R) PRO/1000 Network Connection
udev: renamed network interface eth0 to eth1
parport_pc 00:09: reported by Plug and Play ACPI
parport0: PC-style at 0x378, irq 7 [PCSPP,TRISTATE]
ppdev: user-space parallel port driver
EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: 
Adding 2031608k swap on /dev/sda3.  Priority:-1 extents:1 across:2031608k 
fuse init (API version 7.13)
NET: Registered protocol family 10
lo: Disabled Privacy Extensions
e1000: eth1 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
→ 1549 ~ 1566행을 모두 보여준다.
→ 표시된 내용의 첫행과 마지막행에 e1000이 있다.

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}