1

how to use "grep" command to find a match and to print followup of 10 lines from the match. this i need to get some error statements from log files. (else need to download use match for log time and then copy the content). Instead of downloading bulk size files i need to run a command to get those number of lines.

Marie
  • 51
  • 1
  • 1
  • 5
  • possible duplicate of [grep a file, but show several surrounding lines?](http://stackoverflow.com/questions/9081/grep-a-file-but-show-several-surrounding-lines). You can't because Solaris has an antique grep, but there are a few alternatives listed here. – msw May 26 '14 at 12:14

2 Answers2

8

A default install of Solaris 10 or 11 will have the /usr/sfw/bin file tree. Gnu grep - /usr/sfw/bin/ggrep is there. ggrep supports /usr/sfw/bin/ggrep -A 10 [pattern] [file] which does what you want.

Solaris 9 and older may not have it. Or your system may not have been a default install. Check.

jim mcnamara
  • 16,005
  • 2
  • 34
  • 51
1

Suppose, you have a file /etc/passwd and want to filter user "chetan"

Please try below command:

cat /etc/passwd | /usr/sfw/bin/ggrep -A 2 'chetan'

It will print the line with letter "chetan" and the next two lines as well.

-- Tested in Solaris 10 --

Gilles Heinesch
  • 2,889
  • 1
  • 22
  • 43