awk reg-exp question

Chris Devers cdevers at pobox.com
Wed Jan 28 15:16:45 EST 2004


On Wed, 28 Jan 2004, Joshua Pollak wrote:

> I'm running this command on Linux:
> 
> awk -F"=" '/PARAM/ { print $2 }' Project.cfg
> 
> Which is supposed to return the value of PARAM from a config file with 
> a format like this:
> 
> PARAM=value
> 
> I would expect awk to return:
> 
> value
> 
> I would like this command to ignore commented out values.

Are you looking for a purely awk solution? I personally think it's easier
to cheat by using grep & sed: 

    % grep 'PARAM' file  | \
      grep -v '^ *#'     | \
      sed 's/^[^=]*/\1/' | \
      sed 's/ *#.*//'

It doesn't use awk, but it does what you want.

Awk can probably do this, but IMO if you want to get that fancy and the
shell tools are letting you down, it might be better to just use Perl.




-- 
Chris Devers




More information about the Discuss mailing list