The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 04:21 AM
Using a variable inside a file to cat another. MaestroRage UNIX for Dummies Questions & Answers 3 02-06-2008 02:17 PM
passing a variable inside a variable to a function KingVikram UNIX for Dummies Questions & Answers 2 01-14-2008 08:28 PM
How to replace variable inside the variable mani_um Shell Programming and Scripting 31 08-09-2007 10: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 11:29 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-13-2007
Tártaro Tártaro is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 18
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
  #2 (permalink)  
Old 04-13-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
echo $a | awk -v c=$c '{print $c}'
or
Code:
echo $a | awk '{print $'$c'}'
  #3 (permalink)  
Old 04-13-2007
Tártaro Tártaro is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 18
thank you man.it works perfectly.
  #4 (permalink)  
Old 04-13-2007
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
Code:
awk 'BEGIN { print "Give me some words (Ctrl+C to exit):" }
{ print $c; next }' c=2
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:42 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0