Author Topic: Searching command line output  (Read 453 times)

Offline pags

  • Hero Member
  • *****
  • Posts: 2602
  • Keep it clean.
Searching command line output
« on: September 03, 2010, 10:00:44 AM »
Came a across a little snippet online that I thought was quite neat:
Code: [Select]
lspci -v | awk '/VGA/,/^$/'

I usually use grep, but sometimes, with multi-line output, you don't know how many lines to grab... ???

Looks like using awk, the "^$" looks for a "field delimiter", and the /<PATTERN>/,/<PATTERN2>/ format (note the "comma" between the expressions) brings back everything from <PATTERN> to <PATTERN2> inclusive...

Example:
Code: [Select]
[root@core2pclinux ~]# lspci -v | awk '/VGA/,/^$/'
00:02.0 VGA compatible controller: Intel Corporation Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller (rev 03) (prog-if 00 [VGA controller])
        Subsystem: Dell Device 01d4
        Flags: bus master, fast devsel, latency 0, IRQ 16
        Memory at eff00000 (32-bit, non-prefetchable) [size=512K]
        I/O ports at eff8 [size=8]
        Memory at d0000000 (32-bit, prefetchable) [size=256M]
        Memory at efec0000 (32-bit, non-prefetchable) [size=256K]
        Expansion ROM at <unassigned> [disabled]
        Capabilities: [90] MSI: Enable- Count=1/1 Maskable- 64bit-
        Capabilities: [d0] Power Management version 2
        Kernel driver in use: i915
        Kernel modules: i915, intelfb

And it even works across "records"!
For example:
Code: [Select]
[root@core2pclinux ~]# lspci -v | awk '/945/,/^$/'
00:00.0 Host bridge: Intel Corporation Mobile 945GM/PM/GMS, 943/940GML and 945GT Express Memory Controller Hub (rev 03)
        Subsystem: Dell Device 01d4
        Flags: bus master, fast devsel, latency 0
        Capabilities: [e0] Vendor Specific Information: Len=09 <?>
        Kernel driver in use: agpgart-intel

00:02.0 VGA compatible controller: Intel Corporation Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller (rev 03) (prog-if 00 [VGA controller])
        Subsystem: Dell Device 01d4
        Flags: bus master, fast devsel, latency 0, IRQ 16
        Memory at eff00000 (32-bit, non-prefetchable) [size=512K]
        I/O ports at eff8 [size=8]
        Memory at d0000000 (32-bit, prefetchable) [size=256M]
        Memory at efec0000 (32-bit, non-prefetchable) [size=256K]
        Expansion ROM at <unassigned> [disabled]
        Capabilities: [90] MSI: Enable- Count=1/1 Maskable- 64bit-
        Capabilities: [d0] Power Management version 2
        Kernel driver in use: i915
        Kernel modules: i915, intelfb

00:02.1 Display controller: Intel Corporation Mobile 945GM/GMS/GME, 943/940GML Express Integrated Graphics Controller (rev 03)                                                                                                                           
        Subsystem: Dell Device 01d4                                                                                         
        Flags: bus master, fast devsel, latency 0
        Memory at eff80000 (32-bit, non-prefetchable) [size=512K]
        Capabilities: [d0] Power Management version 2

0c:00.0 Network controller: Intel Corporation PRO/Wireless 3945ABG [Golan] Network Connection (rev 02)
        Subsystem: Intel Corporation Device 1020
        Flags: bus master, fast devsel, latency 0, IRQ 26
        Memory at efdff000 (32-bit, non-prefetchable) [size=4K]
        Capabilities: [c8] Power Management version 2
        Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+
        Capabilities: [e0] Express Legacy Endpoint, MSI 00
        Capabilities: [100] Advanced Error Reporting
        Capabilities: [140] Device Serial Number 00-19-d2-ff-ff-6b-7d-ac
        Kernel driver in use: iwl3945
        Kernel modules: iwl3945

Looks like I'm going to have some quality time with awk, some day!
 ;D

AndrzejL

  • Guest
Re: Searching command line output
« Reply #1 on: September 03, 2010, 10:12:59 AM »
Way cool thanks Dude.

Andy

Offline tschommer

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 1904
  • MLU and BLU (Bacon lovin' user)
Re: Searching command line output
« Reply #2 on: September 03, 2010, 01:52:27 PM »
Great tip, pags! I'm going to be using it often - those multi-liners always gave me fits.

Thanks!
What country can preserve its liberties if its rulers are not warned from time to time that their people preserve the spirit of resistance?
Thomas Jefferson

Offline menotu

  • PCLinuxOS Tester
  • Super Villain
  • *******
  • Posts: 15506
  • ┌∩┐(◕_◕)┌∩┐
Re: Searching command line output
« Reply #3 on: September 03, 2010, 01:58:09 PM »
PCLinuxOS 32bit KDE 4.10.4; kernel-3.4.11-pclos1.bfs & 64bit 3.4.38bfs; NVidia GeForce 8400GS 1GB 310.19 driver

Sony Vaio SVE1513A4ESI Laptop, Intel Core i5, 2.6GHz, 6GB RAM, 750GB, 15.6" Intel HD Graphics 4000