LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   setting up a flag inside awk (https://www.linuxquestions.org/questions/linux-newbie-8/setting-up-a-flag-inside-awk-921587/)

sukhdip 01-02-2012 05:25 AM

setting up a flag inside awk
 
Hi unix gurus....

i need to set a flag inside awk. i tried many methods for that but couldn't succeed :(
like
Code:

echo "flag= " $flag
echo "flag= " ${flag}

and so...but not able to show the flag. help me out.
i'm using a if condition inside awk... help me out with correct syntax to set a flag and use it so that i will be able to return a value back to main script.......
thanks,

rodrifra 01-02-2012 10:04 AM

If you want awk to return a value just print it.

Here is an example

Code:

#!/bin/bash

echo -n "what is your name\? "
read name
message=`echo $name|awk '{if (toupper($1)=="MANOLO") {print "Welcome back Manolo"} else {print $name " I have never seen you around."}}'`

After that pice of code you will have a variable named message in your script with a message that depending on the name entered will be a greeting or another message.

David the H. 01-02-2012 05:44 PM

Your little two-line code sample doesn't really explain your problem. You say it's an awk question, but you only showed us two examples of echo, which is a shell command. How exactly does that relate to awk? And what does "set a flag" mean in this context anyway?

If you want to import a shell value into an awk command, use the -v option.

Otherwise, show us a larger sample of your code, so we can get an idea of how you want to use the variable in context, along with a more detailed, exact description of your actual goal.


All times are GMT -5. The time now is 01:22 AM.