How to use multiple arguments for awk with a shebang (i.e. #!)?

前端 未结 10 834
小蘑菇
小蘑菇 2020-11-22 17:42

I\'d like to execute an gawk script with --re-interval using a shebang. The \"naive\" approach of

#!/usr/bin/gawk --re-interval -f
... awk scri         


        
10条回答
  •  耶瑟儿~
    2020-11-22 18:03

    Why not use bash and gawk itself, to skip past shebang, read the script, and pass it as a file to a second instance of gawk [--with-whatever-number-of-params-you-need]?

    #!/bin/bash
    gawk --re-interval -f <(gawk 'NR>3' $0 )
    exit
    {
      print "Program body goes here"
      print $1
    }
    

    (-the same could naturally also be accomplished with e.g. sed or tail, but I think there's some kind of beauty depending only on bash and gawk itself;)

提交回复
热议问题