Re: Some problem when I define RS (156 Views)
Reply
Super Advisor
Wang,MinJie
Posts: 281
Registered: ‎02-14-2006
Message 1 of 4 (156 Views)

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
Honored Contributor
Steven Schweda
Posts: 9,091
Registered: ‎02-23-2005
Message 2 of 4 (156 Views)

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.
Acclaimed Contributor
Dennis Handly
Posts: 25,188
Registered: ‎03-06-2006
Message 3 of 4 (156 Views)

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.
Acclaimed Contributor
James R. Ferguson
Posts: 21,184
Registered: ‎07-06-2000
Message 4 of 4 (156 Views)

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...
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.