NAWK -- Question

NAWK -- Question

Post by A.L. Cha » Sun, 30 May 1993 23:56:37



Hi :
    Is there anyway that I can append different output to different file using
    one nawk program ?

    e.g  

     in nawkprogram I try to do something like the following :
        { ....
          ...
          print $0 >> "$SOC1.c" }            # append some input to filename.c

        { print $0 >> "$SOC1.h" }            # append other input to filename.h

     in Makefile I try to do something like the following :
                   SOC1 = nawkprogram
            OBJ1 = filename
            step2 : step1
           cat option inputfile | nawk -f $(SOC1)  
            step1:
              setenv OBJ1 $(OBJ1)          # when I try to update , I will get
                                             Error message for this line #

     The purpose is to get 2 output - filename.c and filename.h
     at the same time instead of doing
        cat option inputfile |nawk -f nawkprogram inputfile > filename.h
                        and
        cat option inputfile |nawk -f nawkprogram inputfile > filename.c

     ---------------------------------------------------------------------------
     I would appreciate if everybody can help me out

     Angela.

 
 
 

1. two simple nawk questions, Sunos 4.1.2 and nawk

I am trying to nawk through a file and change in the 20th field the value
of the date from mo/da/year, as in 02/30/1993, to mo/ld/year, as in
02/28/1993( where da is any particular day, even wrong ones, and ld is the
correct last day of the month), and the two problems I can't solve are,
that I can't get the shell wrapper to work like I would like without having
to specify a file on the command line, and I am having trouble finding a
way to print out the line when I am done, using ranges, like $1-$19.

I would like to do:

1)
#! /bin/nawk -f # Call the nawk script without any parameters
BEGIN { FS = "|";
       OFS = "|" }
{ while ( getline <"Data.file" > 0 )

...rest of script...

How can I run this program without having to use:

mysys: ~ $ datefix Data.file

In otherwords, just by typing the script name( without Data.file).

2)
How do I specify a range for a print statement:

print $1-$19,date,$21-$37

Right now it seems I have to have a line like:

print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14...goes on and on till
I wanna scream!

I am sorry if these are obvious questions or FAQ's, but nothing about them
appears in the O'Rielly book, or anywhere else.  I guess the creaters of
nawk expect you to write filters like:

mysys: ~ $ datefix -F\| -f20 < Data.file > Data.file.fixed

but I want to do it my way.
--



{...}!cs.utexas!cactus.org!cheselka (512)452-9412v ( 24hours answer. mach.)

2. Termiox question

3. lex & nawk : Questions

4. Can Not Build Perl

5. nawk question, split string

6. 'ssh node "ls -lR"': consumes all memory on the client!

7. nawk question

8. ShowMe Conferencing package - help needed

9. A Simple nawk Question.

10. nawk question

11. NAWK question

12. A Novice^2 nawk question

13. nawk question