inline GAWK script 
Author Message
 inline GAWK script

How do I write the command line that would get the following GAWK script
to run under Windows 98's command.com?  I want to write the script as a part
of the command line and not use a file.   I've tried various insertions of
; where the newlines occur, and also using double quotes to keep the < from
being interpreted as input file redirection, and I just can't find the exact
way to do it.

BEGIN{}
{
  if (NR < 1000)
     {
        print ""
        next
     }
  if (NR < 2000)
     {
        print $0
     }

Quote:
}

END {}


Fri, 08 Aug 2003 23:26:10 GMT  
 inline GAWK script

Quote:

> How do I write the command line that would get the following GAWK script
> to run under Windows 98's command.com?  

Putting it in a script file and using the construct:
  gawk -f scriptfile.awk

Quote:
> I want to write the script as a part of the command line and not use a file.  

Then you are out of luck, change of underlying system.
command.com as a shell is !$%&*ish

--
  All true believers shall break their eggs at the convenient end.



Fri, 08 Aug 2003 23:49:33 GMT  
 inline GAWK script

Quote:

>How do I write the command line that would get the following GAWK script
>to run under Windows 98's command.com?  I want to write the script as a part
>of the command line and not use a file.   I've tried various insertions of
>; where the newlines occur, and also using double quotes to keep the < from
>being interpreted as input file redirection, and I just can't find the exact
>way to do it.

>BEGIN{}
>{
>  if (NR < 1000)
>     {
>        print ""
>        next
>     }
>  if (NR < 2000)
>     {
>        print $0
>     }
>}
>END {}

I don't know about Win98, but on a Unix system I'd write:

awk 'NR < 1000 {print ""; next}; NR < 2000 ' infile  

Chuck Demas

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

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



Sat, 09 Aug 2003 00:29:58 GMT  
 inline GAWK script

Quote:

> How do I write the command line that would get the following GAWK
> script to run under Windows 98's command.com? I want to write
> the script as a part of the command line and not use a file.
> I've tried various insertions of ; where the newlines occur, and
> also using double quotes to keep the < from being interpreted as
> input file redirection, and I just can't find the exact way to
> do it.

> BEGIN{}
> {
>   if (NR < 1000)
>      {
>         print ""
>         next
>      }
>   if (NR < 2000)
>      {
>         print $0
>      }
> }
> END {}

What follows is untested, because I don't have a Windows 98 machine
with GNU awk on it.

C:\>gawk "NR < 1000 { print blank_line; next } NR < 2000" data.txt

C:\>gawk "NR < 1000 { print \"\"; next } NR < 2000 { print $0 }" data.txt

Can't hurt to try 'em. Good luck.

--
Jim Monty

Tempe, Arizona USA



Sat, 09 Aug 2003 03:57:51 GMT  
 inline GAWK script

Quote:

> How do I write the command line that would get the following GAWK script
> to run under Windows 98's command.com?

Under DOS the command line parsing is done by each and every program,
not by the shell. So it depends on which port of Gawk you are using.

gawk "NR < 1000 {print \"\"; next} NR < 2000"

works fine here with the DJGPP (2.01) port of Gawk.

Regards...
                Michael



Sat, 09 Aug 2003 03:28:37 GMT  
 inline GAWK script

Quote:


> > How do I write the command line that would get the following GAWK script
> > to run under Windows 98's command.com?
> Under DOS the command line parsing is done by each and every program,
> not by the shell. So it depends on which port of Gawk you are using.
>     gawk "NR < 1000 {print \"\"; next} NR < 2000"
> works fine here with the DJGPP (2.01) port of Gawk.

That worked well.  Thanks for the idea of  the \" construction to
keep gawk from terminating the parse!     I'm really happy that
gawk is useable inline even on a "shell" as dumb as MSDOS' command.com...

 - Larry Weiss



Sat, 09 Aug 2003 04:45:23 GMT  
 inline GAWK script


Quote:

>How do I write the command line that would get the following GAWK script
>to run under Windows 98's command.com?  I want to write the script as a part
>of the command line and not use a file.   I've tried various insertions of
>; where the newlines occur, and also using double quotes to keep the < from
>being interpreted as input file redirection, and I just can't find the exact
>way to do it.

>BEGIN{}
>{
>  if (NR < 1000)
>     {
>        print ""
>        next
>     }
>  if (NR < 2000)
>     {
>        print $0
>     }
>}
>END {}

I tried something similar but shorter so that I could show a complete
example using only a few lines:-

C:\>gawk -f - autoexec.bat
NR<6 {
  print NR,length

Quote:
}

^Z
1 46
2 22
3 9
4 64
5 36

C:\>

"gawk -f -" means read the program from standard input

note the use of Control+Z to terminate program input

autoexec.bat is just used as a data file for the example

I am using Windows 95 but I think this may work on Windows 98.

Hope this helps
--
Alan Linton



Sat, 09 Aug 2003 05:11:26 GMT  
 inline GAWK script

: > > How do I write the command line that would get the following GAWK script
: > > to run under Windows 98's command.com?
: > Under DOS the command line parsing is done by each and every program,
: > not by the shell. So it depends on which port of Gawk you are using.
: >     gawk "NR < 1000 {print \"\"; next} NR < 2000"
: > works fine here with the DJGPP (2.01) port of Gawk.
: >

: That worked well.  Thanks for the idea of  the \" construction to
: keep gawk from terminating the parse!     I'm really happy that
: gawk is useable inline even on a "shell" as dumb as MSDOS' command.com...

:  - Larry Weiss

This is absolutely not necessary for GNU awk under Win95/98,
which I have tested under both platforms. As long as you are
not using the MS-DOS redirections arrows or pipes (<, >, or |),
you can match single and double quotes, like this:

   echo. | gawk 'BEGIN{v="there!"}; {print "hello", v}'

If you *must* use a redirection arrow, and you don't want to go
through the rigamarole of excessive quoting, try using the hex
escape sequences:

    \x3C = <     \x3E = >       \x7C = |

so that you can do this:

    echo ">" | awk '/\3E/ { print "matched!"}'

instead of having to do this:

    echo ">" | awk "/>/ { print \"matched!\"}"

The other thing to keep in mind, especially if you decide to
do the "extra escape" route, is that DOS will parse the command
line first, before awk gets to parse it. Redirection (file creation)
and piping is handled first, and then the command tail is passed
to the program (awk) after the redirects or pipes. Thus, you may
safely do this:

    echo x | awk '/x/{print "found --> my letter"}'

but you may NOT do this:

    echo x | awk "/x/{print \"found --> my letter\"}"

and the reason is that DOS/Win9x sees the command line first,
and it doesn't know about the backslash that awk knows about.
DOS will see two strings as protected:

    "/x/{print\"    and    "}"

but what's unprotected is this:

    found --> my letter\

so DOS will try to create a file named " my letter\".
I expect that you understand why, so I'll close for now.
Hope this was helpful to someone!

Kind regards,

Eric Pement



Wed, 27 Aug 2003 08:05:05 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Problem with consecutive running of a gawk script within a loop

2. Using dos/windows environment variables in gawk script

3. gawk executable scripts and ARGV[0]

4. gawk script

5. Problems with Inline/Script Synchronization

6. Inline PHP scripts (onclick, onwhatever)

7. More Wikit woes (was: Re: Wikit / fixpagerefs script (and inline images))

8. Wikit / fixpagerefs script (and inline images)

9. Gawk for win32 slower than Gawk for Dos_32?

10. Gawk bug, gawk won't nawk.

11. gawk 3.0.95, beta for gawk 3.1.0, now available

12. porting inline Watcom asm to MSVC inline asm

 

 
Powered by phpBB® Forum Software