Operating System - HP-UX
1753797 Members
8508 Online
108805 Solutions
New Discussion юеВ

Re: use of sed command in HP-UX vs Linux

 
SOLVED
Go to solution
Gerard Menezes
New Member

use of sed command in HP-UX vs Linux

Hi All,

The following command works fine in Linux

sed -e 's/\(<\/\w*:\w*\>\)./\1>\n/g' "$tempResponseXmlFile" > "$responseXmlFile"

which basically does some scripting and copies the result in the $responseXmlFile.

But when the same is executed in HP_UX, it gives no error, but the $responseXmlFile shows 0 bytes.

For your ref, the $tempResponseXmlFile is attached to this message.

Any ideas on converting the above command for HP-UX sed ?

Thanks
Gerard
8 REPLIES 8
Steven Schweda
Honored Contributor

Re: use of sed command in HP-UX vs Linux

> [...] HP-UX [...]

uname -a

> Any ideas on converting the above command
> for HP-UX sed ?

That would require some thinking. It might
be easier to install GNU "sed" on the HP-UX
system, and then use that.

http://www.gnu.org/software/sed/
James R. Ferguson
Acclaimed Contributor

Re: use of sed command in HP-UX vs Linux

Hi Gerard:

The GNU 'sed' is far superior to HP-UX's as Steven suggested. That said, you could use Perl with a slight modification to your regular expression:

# perl -pe 's/(<\/\w*:\w*\>)./$1>\n/g' file

Notice that we don't need to escape the opening and closing parentheses. In fact, this allows the capture. The result of the capture (the back-slashed '1') is better written as '$1' so we do that too.

We can make things even more readable by using non '/' delimiters:

# perl -pe 's{(<\/\w*:\w*\>).}{$1>\n}g' file

And if you like, you can update "in-place" (which I believe also exists in GNU 'sed'):

# perl -pi.old -e 's{(<\/\w*:\w*\>).}{$1>\n}g' file

The above preserves a copy of the original file named "*.old".

Regards!

...JRF..

Gerard Menezes
New Member

Re: use of sed command in HP-UX vs Linux

Thanks James & Steven for your inputs.
I was actually looking if something could be done using the HP-UX sed itself.
Anyways, since in our project, we are already using GNU "wget", we have decided to also include the GNU "sed", since our scripts need to be compatible with Linux, HP-UX and AIX.
Cheers
Gerard
Dennis Handly
Acclaimed Contributor
Solution

Re: use of sed command in HP-UX vs Linux

>I was actually looking if something could be done using the HP-UX sed itself.

The best I could do is:
sed -e 's@\(\)@\1|@g' "$tempResponseXmlFile" |
tr "|" '\n'

Note: Your input file must have a newline at the end.
Gerard Menezes
New Member

Re: use of sed command in HP-UX vs Linux

Thanks Dennis
Gerard Menezes
New Member

Re: use of sed command in HP-UX vs Linux

As mentioned in my previous comments, we have decided to go with GNU sed, since our scripts need to be compatible with most flavours of UNIX. Thanks all for your efforts. Will use your suggestions in future for HP-UX.
Steven Schweda
Honored Contributor

Re: use of sed command in HP-UX vs Linux

> [...] we have decided to also include the
> GNU "sed", since our scripts need to be
> compatible with Linux, HP-UX and AIX.

If you expect scripts to be portable, then
you probably need to use only features which
are common to all the systems involved. This
might mean using only a subset of features
which are naturally common, or else
installing the feature-rich (GNU) programs
everywhere.

AIX may need some help, too.

One problem with GNUware these days is that
some of it tends to require more of it than
one might expect, leading to more maintenance
than one might expect. Linux systems might
get updates more-or-less automatically, but
the other ones are all your problem. For
portability, there's much to be said for
developing scripts (or any other software) in
the lamest environment you can find.
James R. Ferguson
Acclaimed Contributor

Re: use of sed command in HP-UX vs Linux

Hi (again) Gerard:

> Steven: One problem with GNUware these days is that some of it tends to require more of it than one might expect, leading to more maintenance than one might expect.

And in this case, Perl's regex engine will do everything you need in a fashion that will indeed be portable and virtually, universally available ;-)

Regards!

...JRF...