awk within ksh script 
Author Message
 awk within ksh script

I'd like to put awk code within kshell script so I don't have to call an
awk script from ksh.  How is this done.  I tried putting awk -f  and
code between two '' but it doesn't seem to work.

thanks for your help,

John



Fri, 04 Jan 2002 03:00:00 GMT  
 awk within ksh script


Quote:
>I'd like to put awk code within kshell script so I don't have to call an
>awk script from ksh.  How is this done.  I tried putting awk -f  and
>code between two '' but it doesn't seem to work.

>thanks for your help,

>John

The -f option is for when you want to call a separate script.

Just use the single quotes.  Here's an example:

awk 'NF==1 {print "There was one field found:", $1; next}
     NF==0 {print "No fields were found" ; next}
     {print NF, "fields were found:", $0}' infile

Chuck Demas
Needham, Mass.

--
  Eat Healthy    |   _ _   | Nothing would be done at all,

  Die Anyway     |    v    | That no one could find fault with it.



Fri, 04 Jan 2002 03:00:00 GMT  
 awk within ksh script
You can run awk from within a shell script, just as you run from the command
line.

Example #1
------------
echo "Starting script..."
...
...
awk -f test.awk < in_file.txt > out_file.txt
...
...
exit 0

Example #2
------------
echo "Starting script..."
...
...
echo "This is a test" | awk '{ printf("%s\nWordCount=%d\n", $0, NF) }'
...
...
exit 0

Hope this helps


Quote:
> I'd like to put awk code within kshell script so I don't have to call an
> awk script from ksh.  How is this done.  I tried putting awk -f  and
> code between two '' but it doesn't seem to work.

> thanks for your help,

> John



Sun, 06 Jan 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Using expect from within a ksh script

2. I want to put my awk file into ksh script

3. ksh-awk script problem

4. scripts: ksh calls awk: no stdout?

5. Access to Script Name Within Awk Script

6. Replacing a string from an input file within awk script

7. trying to call awk from within a shell script

8. Run awk from within sed script?

9. shell commands within awk script

10. using Oracle within an awk script

11. Simple awk command within a perl script

12. Running Awk scripts from within VB

 

 
Powered by phpBB® Forum Software