LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 01-02-2012, 06:25 AM   #1
sukhdip
Member
 
Registered: Sep 2011
Posts: 54

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
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,
 
Old 01-02-2012, 11:04 AM   #2
rodrifra
Member
 
Registered: Mar 2007
Location: Spain
Distribution: Debian
Posts: 201

Rep: Reputation: 36
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.
 
Old 01-02-2012, 06:44 PM   #3
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

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


Reply


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 09:48 PM
[SOLVED] awk: how can I assign value to a shell variable inside awk? quanba Programming 6 03-23-2010 03:18 AM
awk inside makefile RudraB Programming 2 12-18-2009 12:51 PM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM
awk inside a makefile linux.fob Programming 2 10-12-2005 05:57 PM


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

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