yong321@yahoo.com
09-08-2005, 07:35 PM
I use GNU utilities for Win32 (http://unxutils.sourceforge.net) on
Windows XP. Combining tail -f and gawk doesn't return anything:
******************************************************
C:\>type test.txt
This is a test.
Second line.
C:\>tail -1 test.txt | gawk "{print $1}"
Second
C:\>tail -f test.txt | gawk "{print $1}"
^C^C
C:\>tail -f test.txt | gawk '{print $1}'
gawk: cmd. line:1: '{print
gawk: cmd. line:1: ^ invalid char ''' in expression
^C
C:\>tail -f test.txt 2>&1 | gawk "{print $1}"
^C^C
C:\>tail -f test.txt 1>&2 | gawk "{print $1}"
This is a test.
Second line.^C^C
******************************************************
So tail | gawk works but tail -f | gawk shows nothing, regardless
whether stderr is duplicated to stdout. Duplicating stdout to stderr
just makes gawk useless. Single quotes are not allowed.
In Cygwin (on this XP machine), using single quotes almost works as
expected (Without a carriage return at the end of the second line, gawk
in Cygwin eats that second line up):
******************************************************
$ cd /cygdrive/c
$ tail -f test.txt | gawk "{print $1}"
This is a test.
$ tail -f test.txt | gawk '{print $1}'
This
******************************************************
Can somebody advise on how to make tail -f test.txt | gawk "{print $1}"
work under DOS without using Cygwin? Thanks.
Yong Huang
William Allen
09-08-2005, 08:09 PM
<yong321@yahoo.com> wrote in message
> I use GNU utilities for Win32 (http://unxutils.sourceforge.net) on
> Windows XP. Combining tail -f and gawk doesn't return anything:
> ******************************************************
> C:\>type test.txt
> This is a test.
> Second line.
> C:\>tail -1 test.txt | gawk "{print $1}"
> Second
>
> C:\>tail -f test.txt | gawk "{print $1}"
> ^C^C
....snip
> So tail | gawk works but tail -f | gawk shows nothing
....snip
Just guessing since I don't use these tools, but there was a possibly
similar problem with GAWK hanging when used in a Batch file that
maintained a textstream open for further throughput (as TAIL -f does)
discussed in alt.msdos.batch.nt (subject line "named pipe" around
4 August 2005). The solution for GAWK was to add the fflush()
statement, something along these lines:
tail -f test.txt | gawk "{print $1};fflush()"
You may want to try it.
--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
From email address not checked. Contact us at http://www.allenware.com/
Bill Marcum
09-08-2005, 09:25 PM
["Followup-To:" header set to comp.lang.awk.]
On 8 Sep 2005 11:35:48 -0700, yong321@yahoo.com
<yong321@yahoo.com> wrote:
> I use GNU utilities for Win32 (http://unxutils.sourceforge.net) on
> Windows XP. Combining tail -f and gawk doesn't return anything:
This is probably because Windows uses fake pipes. "foo | bar" is
executed as "foo>hidden_temp_file; bar<hidden_temp_file"
--
Atlanta makes it against the law to tie a giraffe to a telephone pole
or street lamp.
Eric Pement
09-09-2005, 10:46 PM
yong321@yahoo.com wrote:
> I use GNU utilities for Win32 (http://unxutils.sourceforge.net) on
> Windows XP. Combining tail -f and gawk doesn't return anything:
> ******************************************************
> C:\>type test.txt
> This is a test.
> Second line.
> C:\>tail -1 test.txt | gawk "{print $1}"
> Second
>
> C:\>tail -f test.txt | gawk "{print $1}"
> ^C^C
[ .... ]
> Can somebody advise on how to make tail -f test.txt | gawk "{print $1}"
> work under DOS without using Cygwin? Thanks.
>
> Yong Huang
I also use WinXP and the UnxUtils, but I don't get your results.
*********************************************************************
C:\tmp>ver
Microsoft Windows XP [Version 5.1.2600]
C:\tmp>cat test1.txt
one line
two lines
three lines
four lines
LAST line
C:\tmp>c:\UnxUtils\tail -f test1.txt | c:\UnxUtils\gawk "{print $1}"
one
two
three
four
LAST
^C^C
C:\tmp>c:\UnxUtils\tail --version | head -2
tail (textutils) 2.1
Written by Paul Rubin, David MacKenzie, Ian Lance Taylor, and Jim
Meyering.
C:\tmp>c:\UnxUtils\gawk --version | head -2
GNU Awk 3.1.3
Copyright (C) 1989, 1991-2003 Free Software Foundation.
*********************************************************************
I notice that your input file didn't end with a newline (CR/LF or LF)
so that might cause some display problems. Try a hexdump of the stdout
to see if a misplaced CR in the input might be erasing some of the
output display. I've never used the -f (--follow) switch, so I have
to manually abort the output. Apparently, -f expects a constantly
growing output. I didn't get any different results with
"--follow=name", if that means anything.
However, I *do* get output from the UnxUtils version of tail.exe under
Windows XP Pro and a standard CMD.EXE command interpreter.
--
Eric Pement
Timo Salmi
09-10-2005, 09:02 PM
Eric Pement wrote:
> I also use WinXP and the UnxUtils, but I don't get your results.
Apropos those utilities, I is advisable also to get the update
version
878915 Oct 25 2003 ftp://garbo.uwasa.fi/win95/unix/UnxUpdates.zip
UnxUpdates.zip Updates for UnxUtils GNU utilities for native Win32
3365706 Apr 15 2003 ftp://garbo.uwasa.fi/win95/unix/UnxUtils.zip
UnxUtils.zip GNU utilities for native Win32
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:ts@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip
yong321@yahoo.com
09-11-2005, 02:48 PM
Eric Pement wrote:
>
> I also use WinXP and the UnxUtils, but I don't get your results.
> *********************************************************************
> C:\tmp>ver
>
> Microsoft Windows XP [Version 5.1.2600]
>
> C:\tmp>cat test1.txt
> one line
> two lines
> three lines
> four lines
> LAST line
>
> C:\tmp>c:\UnxUtils\tail -f test1.txt | c:\UnxUtils\gawk "{print $1}"
> one
> two
> three
> four
> LAST
> ^C^C
> C:\tmp>c:\UnxUtils\tail --version | head -2
> tail (textutils) 2.1
> Written by Paul Rubin, David MacKenzie, Ian Lance Taylor, and Jim
> Meyering.
>
> C:\tmp>c:\UnxUtils\gawk --version | head -2
> GNU Awk 3.1.3
> Copyright (C) 1989, 1991-2003 Free Software Foundation.
>
> *********************************************************************
Thanks so much. That's the problem. I was using an old version:
C:\>d:\systools\tail --version | d:\systools\head -1 & d:\systools\gawk
--version | d:\systools\head -1
tail (GNU textutils) 2.0
GNU Awk 3.1.0
I just downloaded the new version tail 2.1 and gawk 3.1.3. The problem
is solved! In fact, it's the problem of tail 2.0. I.e., the new tail
and the old gawk combined still works.
Yong Huang