Redirect from Variable to command line??


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Redirect from Variable to command line??
# 1  
Old 03-27-2006
Power 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  
Old 03-27-2006
echo $i Doesn't work?
if not

echo "xterm -e $i &"
# 3  
Old 03-27-2006
Nope neither worked, it was just dumped back out as a string when echo was called.. but never ran either command??
# 4  
Old 03-27-2006
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  
Old 03-27-2006
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  
Old 03-27-2006
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  
Old 03-27-2006
Bug

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...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

2. Shell Programming and Scripting

How to redirect output of a command to a variable during ftp mode?

Hi, How can I redirect the output of a following command to a variable. ftp myservername ftp> user (username) guptaji 331 Password required for guptaji. Password: ftp> size /home/salil/abc.dat ftp> a='size /home/salil/abc.dat' ?Invalid command I want to redirect value of size to... (1 Reply)
Discussion started by: Salil Gupta
1 Replies

3. Shell Programming and Scripting

Redirect output of command line to for loop

I would like to redirect output of command line in for loop as $line. Output should be processed as line but instead it throw whole output. Could somebody help me on how to redirect output of command line and process it line by line without sending output to any file. below is my code ... (1 Reply)
Discussion started by: tapia
1 Replies

4. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

5. Shell Programming and Scripting

Using redirect for input instead of command line

I have a script that is working when I input parameters from the command line. I was under the assumption that i could use a redirect for the input. script fred.sh: value1=$1 value2=$2 print $value1 $value2 Running from command line: fred.sh 1 2 1 2 Contents of file fred.txt:... (3 Replies)
Discussion started by: djm2112
3 Replies

6. Shell Programming and Scripting

Input variable in command line

i have this script that reads a file "listall_101111" where 101111 varies. awk '{print $0,$1}' listall_101111 | sed -e 's/\(.*\).$/\1/g' | awk '{print $6,$2,$3,$4,$5}' | sort -nrk5 | nawk 'NR==1{m=$5;a++;b=(b)?b:$0;next}$5==m{a++;b=(b)?b:$0}END{for (i in a){print b,a}}' | grep -v ^LG | sort... (4 Replies)
Discussion started by: aydj
4 Replies

7. Shell Programming and Scripting

variable redirect messing up a sed command.

Not sure if that title is decent, but here we go. I'm running this string of commands: qstat -f $1 | sed 's/^*//' | sed -n -e ":a" -e "$ s/\n//gp;N;b a" | sed 's/\\,/,/' | awk -F"PBS_O_WORKDIR=" '{print $2}' | awk -F",PBS_O_SYSTEM" '{print $1}'In case you're curious is takes the output of a PBS... (3 Replies)
Discussion started by: dhibbit
3 Replies

8. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

9. UNIX for Dummies Questions & Answers

redirect stderr and/or stdout to /dev/null from command line

Is it possible to redirect errors at the command line when you run the script such as bash scriptname & 2>/dev/null? (1 Reply)
Discussion started by: knc9233
1 Replies

10. UNIX for Dummies Questions & Answers

redirect command output to variable

Hi, I am looking for a way to redirect the result from a command into a variable. This is the scenario. Using the find command I will be getting multiple records/lines back. Here is the command I am using: find /”path”/ -name nohup.out -print This now is giving me the paths and file... (1 Reply)
Discussion started by: hugow
1 Replies
Login or Register to Ask a Question