LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk command issue (https://www.linuxquestions.org/questions/linux-newbie-8/awk-command-issue-4175434710/)

vicky007aggrwal 10-30-2012 02:10 AM

awk command issue
 
Any idea on hwo to knock out the below error


root="/webroot"
echo $root | awk -v r=$root '{ print "shell root value - " r}'
awk: syntax error near line 1
awk: bailing out near line 1

druuna 10-30-2012 02:25 AM

The above works when using gawk and bash:
Code:

$ root="/webroot"
$ echo $root
/webroot
$ echo $root | awk -v r=$root '{ print "shell root value - " r}'
shell root value - /webroot

Which awk are you using: awk --version or ls -l $(which awk)

And which shell: grep $(id -u) /etc/passwd

grail 10-30-2012 11:36 AM

My question would be ... what is the purpose of the script?

The echo is pointless. Just place BEGIN before the braces.

David the H. 10-30-2012 12:50 PM

For that matter, what's wrong with this?

Code:

echo "shell root value - $root"
Unless you have some other, more complex need for awk that you didn't post?

vicky007aggrwal 10-31-2012 01:22 PM

thanks david ,i just put a random example to seek advise.. related to it i have one complex expression

anyway Thanks a lot all.. my issue resolved


All times are GMT -5. The time now is 09:43 PM.