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
read a variable character by character, substitute characters with something else vipervenom25 UNIX for Dummies Questions & Answers 2 06-06-2008 12:18 PM
comparing values of same variable coolkid Shell Programming and Scripting 2 05-27-2008 02:45 PM
getting values from variable in a loop kriuz Shell Programming and Scripting 3 01-22-2008 02:50 PM
assigning values to a variable trichyselva UNIX for Dummies Questions & Answers 3 12-13-2007 10:55 PM
Substitute Variable mmg2711 UNIX for Dummies Questions & Answers 0 10-26-2007 03:59 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #8  
Old 03-13-2006
Registered User
 

Join Date: Mar 2006
Posts: 15
tmarikle,
I now have and get back. What do I have wrong?

$ var_2=3
$ print "11 10 9 8 7 6 5 4 3 2 1" | awk -v var_2=$var_2 '{gsub(/var_2/," ",$0);print}'
11 10 9 8 7 6 5 4 3 2 1

I can't get this to work. I'm not use to stringing thing together and my scripts have been simple sed types. Sorry for all the notes but indeed thanks very much for the help.

John
Reply With Quote
Forum Sponsor
  #9  
Old 03-13-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Sorry, /var_2/ was treated as a literal.

Code:
$ var_2=3
$ print "11 10 9 8 7 6 5 4 3 2 1" | nawk -v var_2=$var_2 '{gsub(" "var_2" "," ",$0);print}'
11 10 9 8 7 6 5 4 2 1
Reply With Quote
  #10  
Old 03-13-2006
Registered User
 

Join Date: Mar 2006
Posts: 15
tmarikle,
Thankyou so very much.
Reply With Quote
  #11  
Old 03-13-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,016
Quote:
Originally Posted by tmarikle
Sorry, /var_2/ was treated as a literal.

Code:
$ var_2=3
$ print "11 10 9 8 7 6 5 4 3 2 1" | nawk -v var_2=$var_2 '{gsub(" "var_2" "," ",$0);print}'
11 10 9 8 7 6 5 4 2 1
it won't work for 'var_2=1' or 'var_2='11'
Reply With Quote
  #12  
Old 03-13-2006
Registered User
 

Join Date: Mar 2006
Posts: 15
True, I would have to add a space before the 11 and after the 1.
Reply With Quote
  #13  
Old 03-15-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,016
Quote:
Originally Posted by John Rihn
True, I would have to add a space before the 11 and after the 1.
where? In the echo-ed string?
that's cheatin'
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 10:36 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