Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solaris equivalent of -o option of grep on Linux

I run the following on sun Solaris (its run OK on Linux) but not on sun Solaris

name="(WORD = (TCPIP = (PROTOCOL = TCP)(WORD = ALIAS_NAME)(PORT = 10234))"
echo $name | grep -o "(WORD = (TCPIP = (PROTOCOL = TCP)(WORD = ALIAS_NAME)(PORT =  10234))"
grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .

my question which the same option on sun Solaris as the option grep -o (to match string capture)

lidia

like image 458
lidia Avatar asked Sep 01 '10 06:09

lidia


People also ask

What is an alternative to grep?

The findstr command is a Windows grep equivalent in a Windows command-line prompt (CMD). In a Windows PowerShell the alternative for grep is the Select-String command.

What is option in grep command in Linux?

The grep filter searches a file for a particular pattern of characters, and displays all lines that contain that pattern. The pattern that is searched in the file is referred to as the regular expression (grep stands for global search for regular expression and print out). Syntax: grep [options] pattern [files]

How do I grep a file in Solaris?

To search for all the lines of a file that do not contain a certain string, use the -v option to grep . The following example shows how to search through all the files in the current directory for lines that do not contain the letter e.

Does Linux have grep?

Grep is a Linux / Unix command-line tool used to search for a string of characters in a specified file. The text search pattern is called a regular expression. When it finds a match, it prints the line with the result. The grep command is handy when searching through large log files.


2 Answers

Solaris grep doesn't seem to have such an option. If you just need this to run on some solaris boxes, perhaps they got GNU grep installed? (E.g. this one has it under /usr/local/gnu/bin/grep).

If you need this to run under any solaris, you cannot use grep. Perhaps sed and awk can be used?

like image 162
Uli Schlachter Avatar answered Sep 17 '22 18:09

Uli Schlachter


Sun's^W^WOracle's grep doesn't do that. You need to download the GNU grep version, preferably from sunfreeware.com.

like image 44
Kilian Foth Avatar answered Sep 19 '22 18:09

Kilian Foth