Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Odd results in Windows 7x64 gawk

46 views
Skip to first unread message

Steve Graham

unread,
Nov 2, 2012, 1:51:00 PM11/2/12
to
I have a text file from which I need to purge empty lines or lines which
only have <CR><LF>. So I tried:

gawk 'length > 2' < purging.txt

This results in a file named [2'] (without the brackets) which has the
correct info.

I changed it to:

gawk "length > 2" < purging.txt > purging2.txt

and this seemed to work fine.

Why?


Steve

P.S. Running the first example in gawk under ming functioned correctly.

Janis Papanagnou

unread,
Nov 2, 2012, 1:57:30 PM11/2/12
to
On 02.11.2012 18:51, Steve Graham wrote:
> I have a text file from which I need to purge empty lines or lines which only
> have <CR><LF>. So I tried:
>
> gawk 'length > 2' < purging.txt
>
> This results in a file named [2'] (without the brackets) which has the correct
> info.
>
> I changed it to:
>
> gawk "length > 2" < purging.txt > purging2.txt
>
> and this seemed to work fine.
>
> Why?

This is a WinDOS quoting issue; don't blame gawk for that. ;-)

On the WinDOS platform put all non-trivial awk programs in a file
and call that file with awk option -f.

Janis

Kenny McCormack

unread,
Nov 2, 2012, 3:23:27 PM11/2/12
to
In article <k7115q$tbl$1...@speranza.aioe.org>,
While Janis is certainly correct in advising you not to put AWK programs on
the command line in WinDOS, you might be interested in an actual answer to
your "Why?" question.

The answer is that in the WinDOS shell, single quotes don't mean anythng at
all. They are just regular characters. So, when you write:

'length > 2'

WinDOS sees the redirection and produces an output file named 2'

But double quotes do mean something in the WinDOS shell and will, more or
less, do what you expect.

And, of course, when you use mingw, you are running it under a regular Unix
shell, where quoting works as expected, so no worries there. The point of
all this is that this has nothing to do with operating system, and
everything to do with shell.

--
The motto of the GOP "base": You can't be a billionaire, but at least you
can vote like one.

Steve Graham

unread,
Nov 2, 2012, 3:35:25 PM11/2/12
to
Thanks, Kenny. So does gawk just ignore the 1st apostrophe?

BTW, I really appreciate gawk/awk. What a great utility for
accomplishing miracles in just a few characters!


Steve

Luuk

unread,
Nov 2, 2012, 3:40:33 PM11/2/12
to
On 02-11-2012 20:23, Kenny McCormack wrote:
> The point of
> all this is that this has nothing to do with operating system, and
> everything to do with shell.

But the shell has everything to do with the operariting system.....

Whe cannot run cmd.exe on a linux or unix system.

Kenny McCormack

unread,
Nov 2, 2012, 3:59:15 PM11/2/12
to
Actually, you probably could, if you really wanted to, using something like
Wine. And, more to the point, you can certainly run sh-like shells on
WinDOS.

--
Those on the right constantly remind us that America is not a
democracy; now they claim that Obama is a threat to democracy.

Kenny McCormack

unread,
Nov 2, 2012, 4:02:23 PM11/2/12
to
In article <k7179i$ddd$1...@speranza.aioe.org>,
Steve Graham <jsgra...@yahoo.com> wrote:
...
>Thanks, Kenny. So does gawk just ignore the 1st apostrophe?

I had to think for a minute or two to grok what your question was getting
it. Yes, it (*) seems that it must somehow "know" to ignore the single
quote marks.

(*) And by "it", I mean specifically the WinDOS port(s) of GAWK. I don't
imagine it would ignore them on Unix.

>BTW, I really appreciate gawk/awk. What a great utility for
>accomplishing miracles in just a few characters!

Indeed. Quite so.

--
Modern Christian: Someone who can take time out from
complaining about "welfare mothers popping out babies we
have to feed" to complain about welfare mothers getting
abortions that PREVENT more babies to be raised at public
expense.

Luuk

unread,
Nov 2, 2012, 4:09:00 PM11/2/12
to
C:\temp>type purging.txt
test1
test2
test3
C:\temp>"C:\Program Files (x86)\GnuWin32\bin\gawk.exe" 'length > 2' <
purging.txt
gawk: 'length
gawk: ^ invalid char ''' in expression

C:\temp>"C:\Program Files (x86)\GnuWin32\bin\gawk.exe" "length > 2" <
purging.txt
test1
test2
test3

C:\temp>

C:\temp>"C:\Program Files (x86)\GnuWin32\bin\gawk.exe" --version
GNU Awk 3.1.6
Copyright (C) 1989, 1991-2007 Free Software Foundation.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.

C:\temp>

0 new messages