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 > writing to an o...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 2234 of 2236
Post > Topic >>

writing to an output file specified by an ARGV argument

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

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 ;
}' $*

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




 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 Thu May 15 22:05:56 CDT 2008.