Useful GNU grep option

I liked "How to get the serial number of a Sun machine through iLOM" at http://blog.philipp-michels.de/?p=102:

$ ipmitool -v -H {IP} -U root -P {PW} fru | grep /SYS -A 5

FRU Device Description : /SYS (ID 20)
 Product Manufacturer  : SUN MICROSYSTEMS
 Product Name          : SUN FIRE X4200 M2
 Product Part Number   : 602-3891-01
 Product Serial        : 0116SL46F2
 Product Extra         : 080020FFFFFFFFFFFFFF00144F7DB00A

The problem is that the "grep -A" option is not supported by the Solaris default grep.

The solution is to use GNU grep (ggrep at /usr/sfw/bin/ggrep) which is packaged on the Solaris Companion CD (also see http://blogs.sun.com/taylor22/entry/installing_the_solaris_10_os)

While I was searching the www for grep -A, I found many more interesting usage examples, such as finding stack traces for exceptions in Java log files and  finding the text surrounding any ORA- messages in the Oracle alert.log

Update: Solaris 11 installation and usage:

# pkg install gnu-grep

# which ggrep
/usr/bin/ggrep

# ls -l /usr/bin/ggrep
lrwxrwxrwx   1 root     root          15 Jun  2 13:08 /usr/bin/ggrep -> ../gnu/bin/greproot@

For example, some message was repeated

# grep  "repeated 2 times"  /var/adm/messages.*
/var/adm/messages.3:Feb 11 16:43:56 p3231-05 last message repeated 2 times


Which one? Can't use Solaris grep to find the line before the pattern.

# grep -B1 "repeated 2 times"  /var/adm/messages.*
grep: illegal option -- B
grep: illegal option -- 1
Usage: grep [-c|-l|-q] -bhinsvw pattern file . . .


But ggrep does the trick.

# ggrep -B1 "repeated 2 times"  /var/adm/messages.*
/var/adm/messages.3-Feb 11 16:43:54 p3231-05 dlmgmtd[49]: [ID 183745 daemon.warning] Duplicate links in the repository: net0
/var/adm/messages.3:Feb 11 16:43:56 p3231-05 last message repeated 2 times


Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

user12620111

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today