Operating System - HP-UX
1752815 Members
5948 Online
108789 Solutions
New Discussion юеВ

Re: AWK version in hpux 11.11

 
SOLVED
Go to solution
James R. Ferguson
Acclaimed Contributor

Re: AWK version in hpux 11.11

Hi (again):

> OldSchool: did you happen to try the -F and {BEGIN..} methods?

Yes, indeed, they are consistent in HP-UX (11.11) and with GNU's awk (gawk) as I noted. Either Duncan's or Dennis' version work On HP-UX (11.11) or Linux Fedora 9 (GNU Awk 3.1.5) and yield output of "2".

I see the same "1" output using 'gawk' and "2" using HP-UX's 'awk' as noted by the OP.

Warmest Regards!

...JRF...
OldSchool
Honored Contributor

Re: AWK version in hpux 11.11

all of the above seems to imply that, given file "abc" containing:

123#abc
123#def

running

gawk '{FS="#"; print NF, $FN}' abc'

would get

1 123#abc
2 def

????
James R. Ferguson
Acclaimed Contributor

Re: AWK version in hpux 11.11

Hi (again):

Using OldSchool's suggested test:

$ cat /tmp/abc
123#abc
123#def

$ gawk '{FS="#"; print NF, $FN}' /tmp/abc
1 123#abc
2 123#def

...by the way, thanks Peter, for posting the '[gon]awk' tests!

Regards!

...JRF...
Peter Nikitka
Honored Contributor

Re: AWK version in hpux 11.11

Hi again,

correcting the typo in OldSchool suggested test
<< '{FS="#"; print NF, $FN}'
>> '{FS="#"; print NF, $NF}'

leads - of course - to the expected results under Solaris10 here:

gawk '{FS="#"; print NF, $NF}' /tmp/abc
1 123#abc
2 def
oawk '{FS="#"; print NF, $NF}' /tmp/abc
1 123#abc
2 def
nawk '{FS="#"; print NF, $NF}' /tmp/abc
2 abc
2 def
nawk -F'#' '{print NF, $NF}' /tmp/abc
2 abc
2 def
oawk -F'#' '{print NF, $NF}' /tmp/abc
2 abc
2 def
gawk -F'#' '{print NF, $NF}' /tmp/abc
2 abc
2 def

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
James R. Ferguson
Acclaimed Contributor

Re: AWK version in hpux 11.11

Hi (again) Folks:

Yikes, Peter, your eyes are better the mine today. I completely missed the "FN" / "NF" transposition. Here is OldSchool's test (properly):

$ gawk '{FS="#"; print NF, $NF}' /tmp/abc
1 123#abc
2 def

...exactly as he expected it to behave.

Regards!

...JRF...
hwwh1999sina.com
New Member

Re: AWK version in hpux 11.11

Thanks to all for the helping me!

[Chinese]:├и┬░┬в├и┬░┬в├е┬д┬з├е┬о┬╢!
Dennis Handly
Acclaimed Contributor

Re: AWK version in hpux 11.11

>Thanks to all for the helping me!

Since you are new to the forums please read the following about assigning points:
http://forums.itrc.hp.com/service/forums/helptips.do?#33

If you have no further questions about awk/FS, you can also close this thread, indicating you got your answers.
hwwh1999sina.com
New Member

Re: AWK version in hpux 11.11

Very thanks!

I have motified my awk script, use split instead 'FS' in awk {}.

Thanks for :
=====
"Typically, the field and record separators are defined in the BEGIN procedure because you want these values set before the first input line is read. However, you can redefine these values anywhere in the script. In POSIX awk, assigning a new value to FS has no effect on the current input line; it only effects the next input line"

it continues on to say:
"NOTE:
Prior to the June 1996 release of Bell Labs awk, versions of awk for UNIX did not follow the POSIX standard in this regard. In those versions, if you have not yet referenced an individual field, and you set the field separator to a different value, the current input line is split into fields using the new value of FS.
====
Thanks again !
hwwh1999sina.com
New Member

Re: AWK version in hpux 11.11

Thanks all!
Dennis Handly
Acclaimed Contributor

Re: AWK version in hpux 11.11

You have closed the thread without assigning points. You need to make sure push the assign points button first.

You can reopen threads by:
http://forums.itrc.hp.com/service/forums/helptips.do?#41