The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
getting variable inside awk subin_bala Shell Programming and Scripting 1 06-05-2008 01:21 AM
Using a variable inside a file to cat another. MaestroRage UNIX for Dummies Questions & Answers 3 02-06-2008 10:17 AM
passing a variable inside a variable to a function KingVikram UNIX for Dummies Questions & Answers 2 01-14-2008 04:28 PM
How to replace variable inside the variable mani_um Shell Programming and Scripting 31 08-09-2007 07:56 PM
ksh: A part of variable A's name is inside of variable B, how to update A? pa3be Shell Programming and Scripting 4 03-30-2005 08:29 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-13-2007
Registered User
 

Join Date: Mar 2007
Posts: 6
Stumble this Post!
variable inside awk '{print $c}'

i'm trying to do this (in bash darwin);

echo "give me some words: "
read a
c=2 # this is get by other ways
echo $a | awk '{print $c}' # i want to print the column given
# by de $c variable

if there is someone understand what i pretend and see what im doing wrong, please help me.thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 04-13-2007
Registered User
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,397
Stumble this Post!
Code:
echo $a | awk -v c=$c '{print $c}'
or
Code:
echo $a | awk '{print $'$c'}'
Reply With Quote
  #3 (permalink)  
Old 04-13-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milan, Italy/Varna, Bulgaria
Posts: 1,516
Stumble this Post!
Code:
awk 'BEGIN { print "Give me some words (Ctrl+C to exit):" }
{ print $c; next }' c=2
Reply With Quote
  #4 (permalink)  
Old 04-13-2007
Registered User
 

Join Date: Mar 2007
Posts: 6
Stumble this Post!
thank you man.it works perfectly.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:38 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0