![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| read a variable character by character, substitute characters with something else | vipervenom25 | UNIX for Dummies Questions & Answers | 2 | 06-06-2008 12:18 PM |
| comparing values of same variable | coolkid | Shell Programming and Scripting | 2 | 05-27-2008 02:45 PM |
| getting values from variable in a loop | kriuz | Shell Programming and Scripting | 3 | 01-22-2008 01:50 PM |
| assigning values to a variable | trichyselva | UNIX for Dummies Questions & Answers | 3 | 12-13-2007 09:55 PM |
| Substitute Variable | mmg2711 | UNIX for Dummies Questions & Answers | 0 | 10-26-2007 03:59 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Substitute variable values
Hi,
I am trying to redefine the value of a variable based on another variable value. And I want to read in my variables from a enviroment file in the end -- at least I think so. But 1st here's what I want I need to get working: var_1="11 10 9 8 7 6 5 4 3 2 1" var_2=3 var_3=4 So I want var_4="1 2 5 6 7 8 9 10 11 12 13". How do I extract var_2 & var_3 values from var_1 to create var_4? Thanks, John |
| Forum Sponsor | ||
|
|
|
|||
|
Thanks,
I could not get the 1st oneto work but the 2nd version worked minus using awk instead of nawk (nawk not in the system). But you hardcoded 3 & 4 in the gsub's and I need to have them as variables. What is getting substituted will change with every line read from my input file. I'm new to this level of scripts so I will trying to enter variables in the 2nd version and see what happens. Thanks again -- have a good weekend. |
|
|||
|
Substitue variable value
Quote:
The above works but my finished script needs to have a variable in the gsub where the '3' & '4' are. I want to get these values from a input file. I tried things like below but I get Invalid pattern. print "13 11 10 9 8 7 6 5 4 3 2 1" | nawk '{gsub(/$var_2/,," ",$0);gsub(/ var_3/," ");print}' What does this code need to be? Thanks |