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
set variable with another variable? c shell wxornot Shell Programming and Scripting 2 02-23-2008 12:10 PM
shell variable in awk cskumar Shell Programming and Scripting 12 08-20-2007 05:41 AM
Shell Variable - Please help nisha5 Shell Programming and Scripting 4 06-01-2006 01:41 AM
Set Path variable in c shell hassan2 Shell Programming and Scripting 5 04-28-2002 09:08 AM
Knowing the shell, no using $SHELL variable gloprest Shell Programming and Scripting 3 02-09-2002 08:05 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-06-2008
Registered User
 

Join Date: May 2008
Posts: 9
Shell variable with awk

line_no=6
echo 'Phone,' `awk 'NR==$line_no{print;exit}' <filename>`

what is the error in this..

it says..
awk: Field $() is not correct.

The input line number is 1. The file is <filename>.
The source line number is 1.

i want to print the data in the $line_no line of a certain file..
Reply With Quote
Forum Sponsor
  #2  
Old 05-06-2008
Moderator
 

Join Date: Feb 2007
Posts: 2,314
The error is improperly use of a shell variable. One way to use a shell variable with awk:

Code:
line_no=6
awk -v var=$line_no 'NR==var{print "Phone: "$0;exit}' <filename>
Regards
Reply With Quote
  #3  
Old 05-06-2008
Registered User
 

Join Date: May 2008
Posts: 9
thnks man.. it helped
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:20 PM.


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

Content Relevant URLs by vBSEO 3.2.0