Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-02-2012, 05:25 AM   #1
Registered: Sep 2011
Posts: 55

Rep: Reputation: Disabled
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
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.......
Old 01-02-2012, 10:04 AM   #2
Registered: Mar 2007
Location: Spain
Distribution: Debian
Posts: 202

Rep: Reputation: 36
If you want awk to return a value just print it.

Here is an example


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.
Old 01-02-2012, 05:44 PM   #3
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,842

Rep: Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004Reputation: 2004
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use grep inside awk? Helene Programming 10 09-29-2015 08:48 PM
[SOLVED] awk: how can I assign value to a shell variable inside awk? quanba Programming 6 03-23-2010 02:18 AM
awk inside makefile RudraB Programming 2 12-18-2009 11:51 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
awk inside a makefile linux.fob Programming 2 10-12-2005 04:57 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:25 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration