Kees Nuyt escribió:
> On Sat, 16 Feb 2008 10:55:43 -0600, Ted Davis
> ...
> Yes, it's hard to find a gawk with 2way pipes for
> MSWindows, but there is a cygwin gawk version that does.
>
> It is called gawki.exe :
> $ gawki --version
> GNU Awk 3.1.1
> Copyright (C) 1989, 1991-2002 Free Software Foundation.
>
> It also supports 2way pipes to TCP / UDP ports.
Well, my out-of-the box Cygwin build of gawk just support |& without
problem, at least for inet operations:
I:\Trabajos\gawk\webargs>cygwin gawk --version
GNU Awk 3.1.5
Copyright (C) 1989, 1991-2005 Free Software Foundation.
....
Here is a sample code to retrieve argument files from Internet:
===== webargs.awk =====
#------------------------------------------------------------------
# webargs --- retrieve remote argument files via HTTP 1.0
#
# Manuel Collado, http://lml.ls.fi.upm.es/~mcollado,
Public domain
# November, 2006
#
# Based on sample code from gawkinet docs and libraries by J. Kahrs
#
# USAGE
# gawk -f webargs.awk -f myprogram.awk url_or_file_arguments ...
#
# TODO
# Avoid duplicate downloads (cache)
# Handle ports in URLs
# Handle HTTP redirections
# Handle other protocols
BEGIN {
# replace remote arguments with local copies
_rs = RS
_ors = ORS
ORS = RS = "\r\n\r\n"
for (_k = 1; _k < ARGC; _k++) {
_url = ARGV[_k]
if (match(_url,"://[^/]+")) {
printf( "webargs: remote: %s -> ", _url ) > "/dev/stderr"
_protocol = substr(_url, 1, RSTART-1)
if (tolower(_protocol) != "http") {
printf( "'%s' protocol not supported\n", _protocol ) >
"/dev/stderr"
continue
}
_localarg = "webarg~" _k
printf( "local: %s\n", _localarg ) > "/dev/stderr"
_host = substr( _url, RSTART+3, RLENGTH-3 )
_port = 80
_method = "GET"
_service = "/inet/tcp/0/" _host "/" _port
print _method " " _url " HTTP/1.0" |& _service
_service |& getline _header
split( _header, _hfield, "[\\r\\n]+" )
print _hfield[1] > "/dev/stderr"
while ((_service |& getline) > 0)
printf( "%s", $0 ) > _localarg
close(_service)
close(_localarg)
_filename[_localarg] = _url
ARGV[_k]= _localarg
}
}
RS = _rs
ORS = _ors
}
# restore original argument names when processing files
FNR==1 && (FILENAME in _filename) {
FILENAME = _filename[FILENAME]
}
==== list.awk ====
{
print FILENAME, FNR, $0
}
To exercise the code, run:
gawk -f webargs.awk -f list.awk http://sample1
http://sample2
...
Regards.
--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado


|