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
redirect the grep output into the variable mail2sant Shell Programming and Scripting 1 04-08-2008 06:46 AM
Assigning output of command to a variable in shell sankar reddy Shell Programming and Scripting 6 02-27-2008 11:01 PM
assigning nawk output to shell variable user_prady Shell Programming and Scripting 6 11-29-2007 12:01 AM
Redirect Output In Variable ZINGARO UNIX for Dummies Questions & Answers 1 08-02-2006 03:56 AM
redirect command output to variable hugow UNIX for Dummies Questions & Answers 1 06-22-2005 03:43 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-08-2006
dhinge's Avatar
Registered User
 

Join Date: Nov 2006
Location: Salt Lake City, UT
Posts: 19
Stumble this Post!
awk redirect output to shell variable

I'm trying to redirect awk's output to a BASH variable. Currently the statement looks like this

options=`awk '{ while (i < NF) { print $i; ++i } }' answer

but for some reason that makes $options look like this:

1 2 3 4
1
2
3

Now, the input file 'answer' is taken from a dialog checklist. So if I choose option 1, 2, 3, and 4, they are printed to $options twice, but in horizontal, then vertical order. And 4 is gone! Try to explain that.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-09-2006
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,444
Stumble this Post!
i is taking on the values 0 1 2 3
So you print $0 which is the whole record and you never print $4
Reply With Quote
  #3 (permalink)  
Old 12-09-2006
dhinge's Avatar
Registered User
 

Join Date: Nov 2006
Location: Salt Lake City, UT
Posts: 19
Stumble this Post!
I see. The problem is, I need all the values strung together, unspaced. So if the file has 1 2 3 4, I need it to be 1234 in the bash variable. So far I haven't found a way to get awk to print them unspaced.
Reply With Quote
  #4 (permalink)  
Old 12-09-2006
dhinge's Avatar
Registered User
 

Join Date: Nov 2006
Location: Salt Lake City, UT
Posts: 19
Stumble this Post!
!@#$, I finally figured it out. A while loop prints it all funny like that, but a for loop lets me print it unpaced, on one line:

awk '{ for(i=1;i<NF+1;i++) printf $i }' answer
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:40 AM.


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