tail -f | gawk on Windows

  • Thread starter Thread starter yong321
  • Start date Start date
Y

yong321

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
 
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.
 
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 said:
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
 
Eric said:
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
 
Back
Top