awk Newbie question 
Author Message
 awk Newbie question

I have just written my first awk program (strip) to remove certain records
from an input file.
This program does just the job when I execute it from the command line with
an

awk -f strip input_file

command.

However, when I put this command into the script from which I want it to be
called it seems to totally ignore the line & the output file
from the awk program is not created.
The only diference is the input_file is held in a variable name i.e

awk -f strip $INPUT_FILE

Looking around the web & usergroups I could include my awk code "in stream"
but I think it would be neater to leave the
code in it's own file as it will be called from several different scripts &
will therefore only need changing in 1 place in any
changes are required.

Is there anything I am missing about running awk programs from inside
scripts.

Thanks in advance,
Dave

----------------------------------------------------------------------------
--------------
Please remove myteeth before replying



Mon, 20 Jan 2003 03:00:00 GMT  
 awk Newbie question

Quote:

> I have just written my first awk program (strip) to remove certain records
> from an input file.
> This program does just the job when I execute it from the command line with
> an

> awk -f strip input_file

> command.

> However, when I put this command into the script from which I want it to be
> called it seems to totally ignore the line & the output file
> from the awk program is not created.
> The only diference is the input_file is held in a variable name i.e

> awk -f strip $INPUT_FILE

I don't think it's an awk- bus a Shell-Problem - the Variable does not contain
what you
are expecting. Check the content of the variable before executing awk.
In Korn-Shell simply do:
if [ -r "$INPUT_FILE" ]
then awk ...
else print "cannot read '$INPUT_FILE'"
fi

...

--
Quote of the month:
        Perl can do everything Awk can do, but not as elegantly.



Mon, 20 Jan 2003 03:00:00 GMT  
 awk Newbie question

Quote:

> However, when I put this command into the script from which I want it to be
> called it seems to totally ignore the line & the output file
> from the awk program is not created.
> The only diference is the input_file is held in a variable name i.e

> awk -f strip $INPUT_FILE

1) What do you get if you put "echo $INPUT_FILE" right before calling
   awk?
2) Sanity check: awk is in your PATH (when you are inside the script),
   and the script is executable, aren't they?
3) More sanity check: strip is in the current directory, isn't it?

--

"... We work by wit, and not by witchcraft;
 And wit depends on dilatory time." [Shakespeare]



Mon, 20 Jan 2003 03:00:00 GMT  
 awk Newbie question


Quote:
> I have just written my first awk program (strip) to remove certain records
> from an input file.
> This program does just the job when I execute it from the command line
with
> an

> awk -f strip input_file

> command.

> However, when I put this command into the script from which I want it to
be
> called it seems to totally ignore the line & the output file
> from the awk program is not created.
> The only diference is the input_file is held in a variable name i.e

> awk -f strip $INPUT_FILE

> Looking around the web & usergroups I could include my awk code "in
stream"
> but I think it would be neater to leave the
> code in it's own file as it will be called from several different scripts
&
> will therefore only need changing in 1 place in any
> changes are required.

> Is there anything I am missing about running awk programs from inside
> scripts.

> Thanks in advance,
> Dave

> --------------------------------------------------------------------------
--
> --------------
> Please remove myteeth before replying

You have to escape awk temporarily to capture the shell variable. You can
do this by embedding your shell variable as follows:

assuming the contents of a bourne shell script:
---------------------------------------------------------------
$ TEAM=Detroit

awk 'BEGIN {
    team_input = "'$TEAM'"

    print "team_input", team_input

Quote:
}'

----------------------------------------------------------------
Summary: You escape awk  with  the single quote combination embedded
inside of double quotes.

Give this a try.



Tue, 21 Jan 2003 03:00:00 GMT  
 awk Newbie question

Quote:

>You have to escape awk temporarily to capture the shell variable. You can
>do this by embedding your shell variable as follows:

>assuming the contents of a bourne shell script:
>---------------------------------------------------------------
>$ TEAM=Detroit

>awk 'BEGIN {
>    team_input = "'$TEAM'"

yeah, that works. Or you can use something like

awk -v team_input=$TEAM '
  whatever...
'

--
[Trim the no-bots from my address to reply to me by email!]
[ Do NOT email-CC me on posts. Pick one or the other.]

The word of the day is mispergitude



Sun, 26 Jan 2003 03:00:00 GMT  
 awk Newbie question
Thanks all for you help.
Quote:


>>You have to escape awk temporarily to capture the shell variable. You can
>>do this by embedding your shell variable as follows:

>>assuming the contents of a bourne shell script:
>>---------------------------------------------------------------
>>$ TEAM=Detroit

>>awk 'BEGIN {
>>    team_input = "'$TEAM'"

>yeah, that works. Or you can use something like

>awk -v team_input=$TEAM '
>  whatever...
>'

>--
>[Trim the no-bots from my address to reply to me by email!]
>[ Do NOT email-CC me on posts. Pick one or the other.]

>The word of the day is mispergitude



Fri, 31 Jan 2003 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. AWK Newbie Question

2. AWK newbie is looking for a AWK help with his 1st program

3. Newbie awk (sed??) question, regular expressions

4. A Newbie AWK question

5. Newbie question -- to make an awk program act on a collection of files

6. AWK for DOS - NewBie Question

7. newbie awk question

8. Newbie question: how to learn (N)AWK

9. Newbie question on using System() and Awk

10. Newbie AWK Question

11. newbie question on Tcl with awk

12. Newbie Question (Was: Newbie Question...)

 

 
Powered by phpBB® Forum Software