Hi No the jist was that
I wanted to so something like this awk '/regex/ {awk code}' and assign the result to a variable, but i wanted to make the regex from a variable in the program, notice though that I had to place the ' around the /regex/ {awk code}, my problem then is how to organise to place a variable inside that A On Tue, Sep 14, 2004 at 10:22:29AM +1000, Peter Rundle wrote: > Alex, > > >VAR2="$( awk -F, "/$SOMEVARIABLE/ /some/pathtoafile/")" > > As others have posted, if you want to assign the result of running the awk > command to the variable VAR2 then use back quotes. E.G. > > VAR2=`awk -F, $SOMEVARIABLE /some/path/to/afile` > > The output from the awk program will be in VAR2. > > If you just want to use the value in a variable on the command line you > don't need quotes just do; > > MYPATH=/home/user1/datafiles > awk -F, $MYPATH/afile > > or if you still want to save the output from the command. > > RESULT=`awk -F, $MYPATH/afile` > > Put the variable in curly braces when there's no delimiter and the shell > will think you are referencing a different variable, eg. > > MYPATH="/home/user1/datafiles/" > RESULT=`awk -F, $MYPATHafile` > > The example above will try to pass the contents of the variable MYPATHafile > to awk, not what you expect, hence; > > RESULT=`awk -F, ${MYPATH}afile` > > However, if you are trying to pass a variable to awk then use awk's > --assign flag. E.G. > > POS="YES" > RESULT=`awk -F, --assign value=$POS '{ print value }' $MYPATH$FILENAME ` > > Will cause the variable $RESULT to contain YES repeated as many times as > there are row's in the file /home/user1/datafiles/afile > > You only need to use double quotes when there is a space involved, E.G > > NEG="NO" > RESULT=`awk --assign value="$POS or $NEG" $MYPATH$FILENAME` > > If you wanted to pass a literal string that contains a $ then put it in > single quotes > > awk --assign msg='Big $$$s' $MYPATH$FILENAME > > > HTH > > P. > > P.S btw in most of the examples the awk won't actually work because for > clarity I haven't shown any awk program code. >
signature.asc
Description: Digital signature
-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html