PCLinuxOS-Forums
News: ...FLASH!!! ...New PCLinuxOS Testing board now open. Register today! Be an active contributor to the PCLinuxOS future! ... Read all about it now, on THIS forum!!!..
 
*
Welcome, Guest. Please login or register. May 27, 2012, 12:14:13 AM


Login with username, password and session length


Pages: [1]   Go Down
  Print  
Author Topic: Searching command line output  (Read 310 times)
pags
Hero Member
*****
Offline Offline

Posts: 1951


Keep it clean.


« on: September 03, 2010, 11:00:44 AM »

Came a across a little snippet online that I thought was quite neat:
Code:
lspci -v | awk '/VGA/,/^$/'

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

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:
[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:
[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!
 Grin
Logged
AndrzejL
PCLinuxOS Tester
Super Villain
*******
Offline Offline

Posts: 11990


Registered Linux User #490933


WWW
« Reply #1 on: September 03, 2010, 11:12:59 AM »

Way cool thanks Dude.

Andy
Logged

tschommer
PCLinuxOS Tester
Hero Member
*******
Offline Offline

Posts: 1367


PCLinuxOS - without rivals


« Reply #2 on: September 03, 2010, 02:52:27 PM »

Great tip, pags! I'm going to be using it often - those multi-liners always gave me fits.

Thanks!
Logged


ASUS M4N68T-M-LE-V2, AMD Phenom II X6 1055T, 4GB RAM, NVIDIA 460GTS
Network Ralink RT2870, MCP61 HD Audio, kernel 3.2.15-pclos1.bfs
menotu
PCLinuxOS Tester
Super Villain
*******
Offline Offline

Posts: 11986

┌∩┐(◕_◕)┌∩┐


« Reply #3 on: September 03, 2010, 02:58:09 PM »

Nice one pags

This small example is quite good

http://www.pclinuxos.com/forum/index.php?action=post;topic=78973.0;num_replies=2
Logged

If you can keep you head while all around you are losing theirs, then you have misunderstood the situation.

PCLinuxOS 32bit & 64bit; 3.2.17bfs kernel, KDE 4.8.3; nvidia 295.53, Athlon 64 X2 4200+; 4GB Ram; NVidia GeForce 8400GS 1GB; x.org 1.10.4 ; 500GB/320GB
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM