Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Mar 2002 17:39:10 -0500
From:      parv <parv_@yahoo.com>
To:        f-q <freebsd-questions@freebsd.org>
Subject:   awk - any possibility of using a variable in regex
Message-ID:  <20020317223910.GA3245@moo.holy.cow>

next in thread | raw e-mail | index | archive | help
is it impossible to use a variable inside a regex in awk?  i tried
the following w/o any success...

{ echo 'polka dot'; echo 'red dot'; } | \
awk -v type=polka ' BEGIN { dot_type=type } /dot_type/ { print }'

...so i had resorted to perl for now.

actual usage is to kill X applications -- xinit, startx -- (from
/usr/share/skel/dot.xinitrc)...

  ...
  if [ -x /usr/X11R6/bin/fvwm2 ]
  then
    # ...
  elif [ -x /usr/X11R6/bin/twm ]
  then
    # ...
  else
    echo ' neither fvwm2 nor twm is available/executable; exiting...'
    echo ' cleaning up...'

    /bin/ps wwaux | \
    /usr/local/bin/perl -n -e \
      '$usr = $ENV{$USER} ? $ENV{USER} : $ENV{LOGNAME};
       if ( m#^$usr.+\b(?:startx|xinit)\b#o )
       {
         (undef, $pid) = split(/[ ]+/);
         print "$pid\n" if ($pid =~ /^\d+$/);
       }
       ' | \
    /usr/bin/xargs /bin/kill -9

    echo ' ...done'
    exit 1
  fi


  - parv

-- 
 

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020317223910.GA3245>