|
|
Difference between *nix & Win32 output
Platform:
C:\>ver
Microsoft Windows 2000 [Version 5.00.2195]
G:\>gawk --version
GNU Awk 3.1.0
Going through the awk FAQ and converting the *nix examples to GnuWin32
ones. At http://www.gnu.org/software/gawk/manual/gawk-
3.1.1/html_node/Single-Character-Fields.html there is a code sample with
output of:
$ echo a b | gawk 'BEGIN { FS = "" }
> {
> for (i = 1; i <= NF; i = i + 1)
> print "Field", i, "is", $i
> }'
-| Field 1 is a
-| Field 2 is
-| Field 3 is b
But my attempt to a Win32 port is:
C:\>echo a b | gawk "BEGIN { FS = \"\" } { for (i = 1; i <= NF; i = i +
1) print \"Field\", i, \"is\", $i }"
with a result that has an extra line(Field 4).
Field 1 is a
Field 2 is
Field 3 is b
Field 4 is <<== extra output that is different in GnuWin32
What am I doing wrong in this case?
TIA,
Will
--
�Microsoft delenda est!
|
|
0
|
|
|
|
Reply
|
Will
|
2/16/2004 3:21:49 AM |
|
Will Ganz wrote:
> Platform:
> C:\>ver
> Microsoft Windows 2000 [Version 5.00.2195]
> G:\>gawk --version
> GNU Awk 3.1.0
>
> Going through the awk FAQ and converting the *nix examples to GnuWin32
> ones. At http://www.gnu.org/software/gawk/manual/gawk-
> 3.1.1/html_node/Single-Character-Fields.html there is a code sample with
> output of:
>
> $ echo a b | gawk 'BEGIN { FS = "" }
>
>> {
>> for (i = 1; i <= NF; i = i + 1)
>> print "Field", i, "is", $i
>> }'
>
> -| Field 1 is a
> -| Field 2 is
> -| Field 3 is b
>
> But my attempt to a Win32 port is:
>
> C:\>echo a b | gawk "BEGIN { FS = \"\" } { for (i = 1; i <= NF; i = i +
^-- note this space
> 1) print \"Field\", i, \"is\", $i }"
>
> with a result that has an extra line(Field 4).
>
> Field 1 is a
> Field 2 is
> Field 3 is b
> Field 4 is <<== extra output that is different in GnuWin32
>
> What am I doing wrong in this case?
try
C:\>echo a b| gawk "BEGIN { ...
^-- note no space
MS-DOS echo command prints everything up to the end of the command,
including trailing spaces
--
To reply by e-mail, please remove the extra dot
in the given address: m.collado -> mcollado
|
|
0
|
|
|
|
Reply
|
Manuel
|
2/16/2004 12:12:14 PM
|
|
> MS-DOS echo command prints everything up to the end of the command,
> including trailing spaces
Manuel,
Thanks for that tip. It has cleared up a lot of confusion on some of the
other problems that I was having in getting the correct results back from
GnuWin32 gawk.
Regards,
Will
--
�Microsoft delenda est!
|
|
0
|
|
|
|
Reply
|
Will
|
2/17/2004 1:45:20 AM
|
|
Just a quetion shouldn't the field separator be space.
You are passing args a and b to awk and then removing setting the field separator to "".
Irish.
|
|
0
|
|
|
|
Reply
|
irish
|
2/20/2004 8:08:54 PM
|
|
|
3 Replies
102 Views
(page loaded in 0.079 seconds)
|
|
|
|
|
|
|
|
|