Can anyone tell me what the best way is to do this using awk or from
awk? I am using awk because that's the language I am familiar with.
Thanks.
peace,
-*-
charles
If the browser runs Javascript, you can use code somewhat like this
BEGIN{
String = ENVIRON[ "QUERY_STRING" ]
sub( /^[0-9]+=/, "", String )
print "Content-type: text/html\n"
print "<HTML><head><SCRIPT
LANGUAGE=\"JavaScript\"></script></head>"
print "<body><script>location= \"" String
"\";</script></body></HTML>"
}
That script extracts a URL from its argument and returns a page
consisting of a Javascript command to load the URL in the browser.
Actually, that is part pf a two script package that simulates clearing
the browser history for a single page each time the page is loaded.
The other half is
# A CGI script to convert a web page into a new one with fresh links
so
# that is is not necessary to clear all history to reset one page.
# The process is simple: a link to the unmunger and the time are
prefixed
# to each link.
#
# The filespec is passed as the QUERY_STRING
BEGIN{
print "Content-type: text/html\n"
Number = systime()
Fname = ENVIRON[ "QUERY_STRING" ]
while( ( getline < Fname ) > 0 ) {
String = tolower( $0 )
if( String ~ /<a href/ ) {
sub( /"[hH][tT][tT][pP]/,
"\"http://xxx.xxxx.xxx/cgi-bin/unmung.cgi?" Number "=http" )
}
print $0
}
}
(that program assumes that the links are zero or one per line.)
T.E.D. (tda...@gearbox.maem.umr.edu)
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.
Your suggestion seems a bit complex. I will do it if I need to. But
in some experimenting, I have found that a very simple loop like this
works perfectly...
getline dataline < datafile
printf "%s", dataline
while ((getline dataline < datafile ) > 0)
printf "\n%s", dataline
Am I making a mistake doing something like this? It worked even on a 16
MB file...
Appreciate your advice.
peace,
-*-
charles
You asked about binaries. That works for ASCII files - files of mime
type text/plain and text/html, but not necessarily for binaries:
image, octet/stream, etc. - you can't count on getline or printf()
being able to handle arbitrary strings of bytes or of the browser to
render them properly once they have been treated as text. Some
versions of awk-type programs have a limit on line length, and will
treat longer strings without \n as multiple lines - your code would
corrupt those files by adding stray \ns inside the strings.
T.E.D. (tda...@gearbox.maem.umr.edu - e-mail must contain "T.E.D." or my .sig in the body)
I'd suggest that you use gawk, and look at the BINMODE variable.
Awk is intended to process text not binaries.
What you want might be easily done with a compiled C program.
Chuck Demas
--
Eat Healthy | _ _ | Nothing would be done at all,
Stay Fit | @ @ | If a man waited to do it so well,
Die Anyway | v | That no one could find fault with it.
de...@theworld.com | \___/ | http://world.std.com/~cpd
BTW: I once did what you suggest and observed interesting discrepancies
between gawk and C compiler output, I hope gawk uses doubles for storing
FP numbers...
On Tue, 23 Mar 2004 18:30:43 +0000 (UTC), Charles Demas
<de...@TheWorld.com> wrote:
> In article <c3f5o5$fff$1...@reader1.panix.com>,
> Charles M. Kozierok <ix...@PCGuide.com> wrote:
>> I want to use awk to create a CGI program that will read a file from my
>> server and output it to a user's browser. These will be binary files and
>> quite large.
>>
>> Can anyone tell me what the best way is to do this using awk or from
>> awk? I am using awk because that's the language I am familiar with.
>
> I'd suggest that you use gawk, and look at the BINMODE variable.
>
> Awk is intended to process text not binaries.
>
> What you want might be easily done with a compiled C program.
>
>
> Chuck Demas
>
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/