Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.os.linux.misc > #1290

Re: Re (3): HOW2 pass args to awk? and more

From Ralf Fassel <ralfixx@gmx.de>
Newsgroups comp.os.linux.misc, comp.lang.awk
Subject Re: Re (3): HOW2 pass args to awk? and more
Date 2011-05-31 14:35 +0200
Message-ID <yga1uzfrqso.fsf@gepard2.akutech-local.de> (permalink)
References <pan.2011.05.29.17.46.08@thedarkdesign.free.fr.INVALID> <iruv09$40j$1@dont-email.me> <4de4cb6c$0$17785$426a34cc@news.free.fr>

Cross-posted to 2 groups.

Show all headers | View raw


* Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID>
| awk 'BEGIN { 
| 	arg1 = ARGV[1]
| 	arg2 = ARGV[2]
| 	arg3 = ARGV[3]
| 	print "arg1=" arg1
| 	print "arg2=" arg2
| 	print "arg3=" arg3
| }
| ' $1 $2 $3

This will only work if you don't do any work in the awk script.  The $1
$2 $3 in that place on the awk command line will be interpreted by awk
as filenames to read.

To pass values to awk, use the -v switch.

  $ cat script
  #!/bin/sh
  printf "In script: 1,2,3==$1,$2,$3\n"
  awk -v arg1=$1 -v arg2=$2 'BEGIN { print arg1, arg2 }'
  $ ./script foo bar
  In script: 1,2,3==dog,cat,rain
  dog cat

R'

Back to comp.os.linux.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: HOW2 pass args to awk? no.top.post@gmail.com - 2011-05-17 06:27 +0000
  Re: HOW2 pass args to awk? Janis Papanagnou <janis_papanagnou@hotmail.com> - 2011-05-17 09:12 +0200
    Re: HOW2 pass args to awk? Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> - 2011-05-17 00:21 -0700
      Re: HOW2 pass args to awk? Harold Stevens <wookie@jimbo.localdomain> - 2011-05-17 09:17 -0500
      Re: HOW2 pass args to awk? Aragorn <aragorn@chatfactory.invalid> - 2011-05-17 17:36 +0200
    Re (2): HOW2 pass args to awk? no.top.post@gmail.com - 2011-05-29 15:56 +0000
      Re: Re (2): HOW2 pass args to awk? Bill Marcum <bill@lat.localnet> - 2011-05-29 13:05 -0400
        Re (3): HOW2 pass args to awk? no.top.post@gmail.com - 2011-05-30 02:22 +0000
          Re: Re (3): HOW2 pass args to awk? Aragorn <aragorn@chatfactory.invalid> - 2011-05-30 05:09 +0200
  Re: HOW2 pass args to awk? Bill Marcum <bill@lat.localnet> - 2011-05-17 07:55 -0400
    Re (2): HOW2 pass args to awk? no.top.post@gmail.com - 2011-05-29 15:56 +0000
      Re: Re (2): HOW2 pass args to awk? Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-05-29 17:46 +0000
        Re (3): HOW2 pass args to awk? no.top.post@gmail.com - 2011-05-30 02:22 +0000
          Re: Re (3): HOW2 pass args to awk? Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-05-30 09:01 +0000
          Re: Re (3): HOW2 pass args to awk? and more Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-05-31 11:05 +0000
            Re: Re (3): HOW2 pass args to awk? and more Ralf Fassel <ralfixx@gmx.de> - 2011-05-31 14:35 +0200
              Re: Re (3): HOW2 pass args to awk? and more Ed Morton <mortonspam@gmail.com> - 2011-05-31 07:56 -0500
              Re: Re (3): HOW2 pass args to awk? and more Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-05-31 14:14 +0000
                Re: Re (3): HOW2 pass args to awk? and more Ralf Fassel <ralfixx@gmx.de> - 2011-06-01 10:41 +0200
              Re (4): HOW2 pass args to awk? and more no.top.post@gmail.com - 2011-06-06 10:26 +0000
                Re: Re (4): HOW2 pass args to awk? and more Loki Harfagr <l0k1@thedarkdesign.free.fr.INVALID> - 2011-06-06 14:01 +0000
            Re (4): HOW2 pass args to awk? and more no.top.post@gmail.com - 2011-06-06 04:58 +0000

csiph-web