Operating System - HP-UX
1748195 Members
5173 Online
108759 Solutions
New Discussion юеВ

Re: Some problem when I define RS

 
Wang,MinJie
Super Advisor

Some problem when I define RS

Hi all,
I've run this on HP-UX and Solaris and it doesn't work while it actually works on Linux.
Pls check the following details:
*****************************************
$ more extract_test.dat
iTEM_ID||column_value||column1||colomn2@@
1111||aaaa||bbb||ccc@@
2222||cccc||ddd||eee@@

$ nawk 'BEGIN{FS="[|][|]";OFS="||";RS="@@\n";ORS="@@\n"}{print $0}' extract_test.dat
iTEM_ID||column_value||column1||colomn2@@
@@

1111||aaaa||bbb||ccc@@
@@

2222||cccc||ddd||eee@@
@@

@@
******************************************

Do you see that?

It seems that The shell doesn't recognize "@@\n" as record separator.

On Linux it's more like:
*******************************************
$ nawk 'BEGIN{FS="[|][|]";OFS="||";RS="@@\n";ORS="@@\n"}{print $0}' extract_test.dat
iTEM_ID||column_value||column1||colomn2@@
1111||aaaa||bbb||ccc@@
2222||cccc||ddd||eee@@
*******************************************

Do you have any idea to modify the command so I can have the same result on Solaris as on
Linux?

Thanks in advance
3 REPLIES 3
Steven Schweda
Honored Contributor

Re: Some problem when I define RS

> It seems that The shell doesn't [...]

The shell or "nawk"?

"nawk" version on each system? OS version on
each system? (The OS version probably
doesn't matter, except as it might offer a
clue as to what you're using for "nawk"
everywhere, in case "nawk" came with one or
more of the OS's.)

> Do you have any idea to modify the command
> so I can have the same result on Solaris as
> on Linux?

Use the same ("nawk") program on each system,
and you probably wouldn't need to modify the
command anywhere?

If I were asking a question like that on an
HP-UX forum, I'd probably phrase it
differently.
Dennis Handly
Acclaimed Contributor

Re: Some problem when I define RS

It seems that GNU awk works the way you want.
Otherwise, each line seems to be broken into 3 parts, the original and two blank lines.
James R. Ferguson
Acclaimed Contributor

Re: Some problem when I define RS

Hi:

OK, so it seems taht the input can be parsed about and recomposed to produce the same output on some platforms. Now, what are you really trying to solve?

It seems that 'awk' differs in its behavior on various opearating systems:

http://www.shelldorado.com/articles/awkcompat.html

If you want a tool that gives highly *consistent* behavior on a large number of platforms, *and* has superior regular expression support: use Perl.

Regards!

...JRF...