Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

awk reg-exp question



It doesn't have to be a purely awk solution, and either your's or 
Duane's solution is probably sufficient. I'm trying to avoid putting 
the code into a perl script however, because the value that is 
extracted needs to be placed in a shell variable from a source'd bash 
script. Basically, we have a build system that relies on some 
environment variables. I want the user to run:

source SetupEnvironment.bsh

and have the script extract the config values from a personal config 
file (~/.project.cfg) and set those variables up in the shell. I'd 
rather not have SetupEnvironment.bsh call any other files, so awk/sed 
solutions are best.

As a tanget, there is no standard environment variable that specifies 
what terminal program the user prefers, is there? IE, konsole, xterm, 
etc? It could avoid this whole mess if people could just run 
./SetupEnvironment.bsh and be presented a whole new terminal with the 
proper environment.

As it stands now, they need to start their terminal and source the 
environment. Yuck.

-Josh


On Jan 28, 2004, at 3:16 PM, Chris Devers wrote:

> 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
>
> _______________________________________________
> Discuss mailing list
> Discuss at blu.org
> http://www.blu.org/mailman/listinfo/discuss
>

-- 
Bush/Cheney '04:
The last vote you'll ever have to cast.





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org