Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: writing to ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 2234 of 2236
Post > Topic >>

Re: writing to an output file specified by an ARGV argument

by Francky Leyn <francky.leyn@[EMAIL PROTECTED] > May 11, 2008 at 09:17 PM

pk wrote:
> 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).

I already though about this.
Myproblem: I don't remember the differece,
and I don't find it back in my notes/manuals.
What is the diffence between $* and "$@[EMAIL PROTECTED]
" is sh?


>> 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.
>




 4 Posts in Topic:
writing to an output file specified by an ARGV argument
Francky Leyn <francky.  2008-05-11 18:50:12 
Re: writing to an output file specified by an ARGV argument
pk <pk@[EMAIL PROTECTE  2008-05-11 20:04:09 
Re: writing to an output file specified by an ARGV argument
Francky Leyn <francky.  2008-05-11 21:17:00 
[OT] Re: writing to an output file specified by an ARGV argument
Janis <janis_papanagno  2008-05-11 18:01:39 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 0:40:24 CDT 2008.