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 > 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 09:26 AM
Redirect to variable MrAd UNIX for Dummies Questions & Answers 2 05-07-2007 04:18 PM
redirect stderr and/or stdout to /dev/null from command line knc9233 UNIX for Dummies Questions & Answers 1 01-25-2007 12:24 PM
redirect command output to variable hugow UNIX for Dummies Questions & Answers 1 06-22-2005 06:43 AM
Passing the command line argument in a variable rkumar28 Shell Programming and Scripting 1 05-26-2004 03:02 PM

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 03-27-2006
ugh ugh is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 7
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
  #2 (permalink)  
Old 03-27-2006
senthilk615 senthilk615 is offline
Registered User
  
 

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

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

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

Join Date: Sep 2004
Location: USA
Posts: 511
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.
  #5 (permalink)  
Old 03-27-2006
ugh ugh is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 7
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.
  #6 (permalink)  
Old 03-27-2006
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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}"
  #7 (permalink)  
Old 03-27-2006
ugh ugh is offline
Registered User
  
 

Join Date: Mar 2006
Posts: 7
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...
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 07:56 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