On Mon, 13 Sep 2004, Alexander Samad wrote:

I am trying to do something like this

#!/bin/bash

SOMEVARIABLE
VAR2="$( awk -F, "/$SOMEVARIABLE/ /some/pathtoafile/")"

Now I have problems with my " I can't use ' because I want SOMEVARIABLE
to be subsituted  I have tried

VAR2="$( awk -F, \"/$SOMEVARIABLE/ /some/pathtoafile/\")"

but it starts going haywire!

Are you sure you don't want:

VAR2="$( awk -F, \"/$SOMEVARIABLE/\" /some/pathtoafile/)"

i.e. you're not giving awk the file as a separate argument?

Another way of achieving this if you've got quoting issues is to make it an awk variable:

VAR2="$( awk -F, -v somevar=\"$SOMEVARIABLE\" '$0 ~ somevar {awk expr}' 
/some/pathtoafile/)"

Oh look what google has:
"6.2 Using Shell Variables in Programs"
http://www.gnu.org/software/gawk/manual/html_node/Using-Shell-Variables.html

Cheers,

 - Simon
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to