Home
| Calendar
| Mail Lists
| List Archives
| Desktop SIG
| Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU |
Joshua Pollak wrote: > [...] > Well, this is a fairly rational idea. However, the one issue is that > each line is prepended by a platform modifier: > > win32:PARAMETER=myParam > unix:PARAMETER=myParam Are you trying to extract the value of a single PARAMETER, or simply set all of them? > I guess on Unix I could do something like: > > sed -e /#.*// user.cfg | sed -e /win32.*// | sed -e /macx.*// | source I tried the following: 1. I created a file (test.cfg) containing: unix:PARM1="Parm1UNIX" # Line1 comment # win32:PARM1="Parm1WINDOWS" # Line2 comment unix:PARM2="Parm2UNIX" win32:PARM2="Parm2WINDOWS" unix:PARM3="Parm3UNIX" # Line5 comment win32:PARM3="Parm3WINDOWS" # Line6 comment 2. I created a small shell script containing: #!/bin/sh PATH="/bin:/usr/bin:/usr/local/bin" grep "$1:$2" | awk ' /^[^#].*$/ { match( $0, /(win32|unix)\:(.+)="(.+)"/, arr ) printf "%s", arr[3] }; ' Note that parameter values within the config file MUST be quoted. Comments (or anything else) after the quoted portion are silently dropped. I suspect awk could actually eliminate the need for grep altogether, but I've really only started working with it myself. 3. I ran the program as follows: cat test.cfg | ./test.sh win32 PARM3 which returned: Parm3WINDOWS Is that along the lines of what you're after? - Bob
BLU is a member of BostonUserGroups | |
We also thank MIT for the use of their facilities. |