lex & nawk : Questions

lex & nawk : Questions

Post by A.L. Ch » Sun, 18 Jul 1993 14:48:43



Hi :

  Does anybody know how to convert nawk code to lex code ?

  such as
  in nawk
  ---------------------------
  BEGIN {}
  $1 ~ /^\.EUS$/ {
  Warning(".EUS") ;
  Usr_Dpr_Handle(type["usr_summary"],type["usr_exten"], "usr_summary","U"
  ) ;
  function Warning (t) {
    if ( NF != 1 ) {

          t = sprintf(" Line %s WARNING :The strings following by document token \
                %s will be ignored !! ", which_line, t ) ;

                print t >  "nawk.log" ;                     # direct to nawk.log
                system("echo" t) ;                              # pipe to shell
        }
 }  # end of Warning

        END{}
        ------------------------------------------------------------------------
        1. Does lex use $1 or NF
        if not , is there any similar build-in functions  in lex ?

        NOTE :
        $ means a field separated by white  space in a input line
        NF is the number od fields in a input line

        eg. if the input line is as following :
                This is test data

        -----------------------------------------------
                Then $0 = This is test data
                         $1 = This
                         $2 = is
             $3 = test
                         $4 = data
                         NF = 4

Thanks in advances

-- 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. 2.2.9 Kernel and my Modem

3. LEX Error when run nawk to compile program

4. Linux Frequently Asked Questions with Answers (Part 6 of 6)

5. Followup YACC & LEX Question

6. shell command to replace string in text files ?

7. Yacc & Lex Question

8. SSH password authentication fails on AIX 4.3

9. Where can I get origianl AT&T lex & yacc source?

10. Wanted - additional tutorials & documentation on Lex & Yacc

11. Lex maximum - Error when compiling with "lex"

12. print 1st & 2nd line using nawk...

13. Sequential Numbers & nawk