![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
|||
|
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.
|
|
|||
|
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... |
|||
| Google The UNIX and Linux Forums |