Grep works on Linux but fails on Solaris

Hi,

On linux i have the below command working fine.

grep -o '<name>.*</name>' deploy.tmp | sed 's/\(<name>\|<\/name>\)//g' deploy.tmp

But the same is failing on Solaris

uname -a
SunOS mymac 5.10 Generic_150400-23 sun4v sparc sun4v

Can you tell me how can i get it work on Solaris ? Whats the alternate to grep -o ?

Assuming that there is no more than one "name" tag on a line in deploy.tmp and that no line in deploy.tmp contains more than 2047 bytes, the following should work:

sed -n -e 's/^.*<name>//' -e 's|</name>.*$||'p deploy.tmp

If more than one "name" tag can appear in your input, please show us a sample of your input and the output you want to produce from that input.

1 Like

Sure, I can check that and let you know tomorrow.

It works !! Thank you !

grep -o on Linux is sed lite for lazy people on Solaris :slight_smile: Perhaps your Solaris has /usr/sfw/bin/ggrep which supports the -o option.

1 Like

I think that .* at the beginning or end does not need an anchor ^ or $

The following ensures that <name> is left from </name> i.e. is more close to the original grep expression.

sed -n 's|.*<name>\(.*\)</name>.*|\1|p' deploy.tmp

if you have perl on solaris...

perl -ne 'if (/<name>(.*)<\/name>/) {print "$1";}' deploy.tmp