1

I searched a lot over google and stackoverflow/serverfault, but I was not able to find a corresponding to "-m" option in the bash shell. I need to fetch only the first result with the grep. Is this possible in the sun-os/solaris?

2 Answers2

5

There is no -m option to the Solaris grep. The -m N switch stops reading a file after N lines have been matched. If all you want is N lines of output then you could use

grep test file | head -N 

where N is the number of lines of output that you want.

user9517
  • 114,104
  • 20
  • 206
  • 289
2

You would need GNU grep to use the -m option. You could use awk or sed in Solaris instead, if you do not want to use GNU grep:

awk '$0 ~ var{print;exit}' var=$string mytextfile
colealtdelete
  • 6,009
  • 1
  • 29
  • 34