On Sunday 11 May 2008 18:50, Francky Leyn wrote:
> Hello,
>
> I want to write (print, printf) to /dev/stdout or a file
> depending on the arguments given to awk:
>
> fig_diagnosis:
>
> #! /bin/sh
> gawk '
> BEGIN {
> # ARGV[0] = "gawk"
> # ARGV[1] = input_file.fig
> # ARGV[2] = diagnosis_file.txt
> if (ARGC > 3) {
> print "Usage: fig_diagnosis [input_file.fig [output_file.txt]]"
> print "Eg: fig_diagnosis input_file.fig diagnosis_file.txt"
> print " fig_diagnosis input_file.fig"
> print " fig_diagnosis < input_file.fig > diagnosis_file.txt"
>
> exit -1 ;
> }
>
>
> # ARGC=1: fig_diagnosis; no arguments -> nothing to be done, output =
> /dev/stdout
> # ARGC=2: fig_diagnosis input_file.fig -> nothing to be done, output =
> /dev/stdout
> # ARGC=3: fig_diagnosis input_file.fig diagnosis_file.txt -> set input +
> output
>
> output = "/dev/stdout"
> if (ARGC == 3) {
> output = ARGV[2] ;
> ARGV[2] = "" ;
> } ;
>
> print "hello world" > output
>
> exit ;
> }' $*
Better change the $* to "$@[EMAIL PROTECTED]
" (with the double quotes).
> For some reason, if I specify an output file, thing go wrong.
> I find this strange because in the pinguin book, the following
> construct is declared legitimate:print $1 > $3
>
> What is wrong?
>
> $ fig_diagnosis < roots_1.fig
> hello world
>
> Francky Leyn@[EMAIL PROTECTED]
/cygdrive/c/Documents and Settings/Francky Leyn/My
> Documents/professional/fig
> $ fig_diagnosis roots_1.fig
> hello world
>
> Francky Leyn@[EMAIL PROTECTED]
/cygdrive/c/Documents and Settings/Francky Leyn/My
> Documents/professional/fig
> $ fig_diagnosis roots_1.fig output.txt
> ' (No such file or directory)an't redirect to `output.txt <============
Your script works for me, but I'm under linux, not cygwin as it seems you
are. Try doing the modification suggested above, although I think that is
not your problem.
--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.


|