The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
after grep i want to redirect it to some variable mail2sant Shell Programming and Scripting 2 04-07-2008 06:26 AM
Redirect to variable MrAd UNIX for Dummies Questions & Answers 2 05-07-2007 01:18 PM
redirect stderr and/or stdout to /dev/null from command line knc9233 UNIX for Dummies Questions & Answers 1 01-25-2007 08:24 AM
redirect command output to variable hugow UNIX for Dummies Questions & Answers 1 06-22-2005 03:43 AM
Passing the command line argument in a variable rkumar28 Shell Programming and Scripting 1 05-26-2004 12:02 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-27-2006
ugh ugh is offline
Registered User
 

Join Date: Mar 2006
Posts: 7
Stumble this Post!
Red face Redirect from Variable to command line??

The following creates a needed awk command from some preexisting variables and stores it in the variable i. I then redirect it to a new file change the permission on the file and run it as a script.

How can I do a simple redirect on this variable to the command line, instead of creating a new file??

i="awk -F\"$dell\" 'BEGIN{OFS=FS}{print $output}' $filename"

echo $i > temp.sh
chmod 700 temp.sh
temp.sh
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-27-2006
Registered User
 

Join Date: Mar 2006
Posts: 16
Stumble this Post!
echo $i Doesn't work?
if not

echo "xterm -e $i &"
Reply With Quote
  #3 (permalink)  
Old 03-27-2006
ugh ugh is offline
Registered User
 

Join Date: Mar 2006
Posts: 7
Stumble this Post!
Nope neither worked, it was just dumped back out as a string when echo was called.. but never ran either command??
Reply With Quote
  #4 (permalink)  
Old 03-27-2006
bhargav's Avatar
Registered User
 

Join Date: Sep 2004
Location: USA
Posts: 511
Stumble this Post!
Quote:
Originally Posted by ugh
The following creates a needed awk command from some preexisting variables and stores it in the variable i. I then redirect it to a new file change the permission on the file and run it as a script.

How can I do a simple redirect on this variable to the command line, instead of creating a new file??

i="awk -F\"$dell\" 'BEGIN{OFS=FS}{print $output}' $filename"

echo $i > temp.sh
chmod 700 temp.sh
temp.sh
Can you try by substituting real values for $dell and $output and try instead of variables.
Reply With Quote
  #5 (permalink)  
Old 03-27-2006
ugh ugh is offline
Registered User
 

Join Date: Mar 2006
Posts: 7
Stumble this Post!
The command runs fine, I just want to run it from the variable instead rebuilding it in a seperate file and running it. The thing is i am dynamically building the $output variable from another awk command and you have to pass all outside variables into awk using -v output=$output. If $output = $2,$3,$1 then awk no longer recognizes the command as accessing its own variables but instead sees it as just a string.
Reply With Quote
  #6 (permalink)  
Old 03-27-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
this is a bit confusing, but interesting....

could you elaborate on your example a bit more, pls!

also:
Code:
i="awk -F\"$dell\" 'BEGIN{OFS=FS}{print $output}' $filename"
eval "${i}"
Reply With Quote
  #7 (permalink)  
Old 03-27-2006
ugh ugh is offline
Registered User
 

Join Date: Mar 2006
Posts: 7
Stumble this Post!
Smile

This script takes a data file and allows you to remove the columns you dont want.

runme.sh datafile.txt "|" 2,4

This will ouput only data that would fall under 2nd and 4th column

filename=$1
dell=$2
keep=$3

echo $keep | awk -F"," '{ORS=" " }{OFS=""}{gtw=","} {for(i=1;i <=NF;i++){ print
"$",$i,gtw; if((i+1) == NF) gtw="" } }' | read output

i="awk -F\"$dell\" 'BEGIN{OFS=FS}{print $output}' $filename"

echo $i>temp.sh
chmod 700 temp.sh
temp.sh
rm temp.sh

Its just alot easier building the awk command this way.
Thank you very much vgersh99...
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 09:26 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