![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sed to replace text with a variable | orahi001 | UNIX for Dummies Questions & Answers | 1 | 03-06-2008 09:25 PM |
| replace with value of variable using SED | prvnrk | Shell Programming and Scripting | 2 | 01-13-2008 11:13 AM |
| How to replace variable inside the variable | mani_um | Shell Programming and Scripting | 31 | 08-09-2007 10:56 PM |
| Force Input in User Defined Variable | earnstaf | Shell Programming and Scripting | 10 | 06-20-2007 08:35 AM |
| environment variable is not defined | alien12 | Linux | 0 | 02-09-2006 11:12 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Replace variable with a user defined variable
I have a file that has a list of entries in a column
x z z z x y z The column can have any length and any number of any strings. I need to replace each unique string with a user defined number. I can filter the unique entries out using awk '{if (NF==5) print $2}' file | uniq | nl > list.tmp which would give 1 x 2 y 3 z I then want to ask the user 'what do you want to replace x with? what do you want to replace y with?' and so on. I then set up a loop to read each line in the file as a variable and loop over these and replace each one with the user input Y=1 while [ $Y -le $Nspecies ]; do #Nspecies is 3 in this case species=`grep "$Y" species.tmp | awk '{print $2}'` #pick species in turn echo "Enter vibration amp. for species" $species #user defined replacement read amp sed s/"$species"/"$amp"/ speciesorder.txt >> $outfile #do switch replace Y=$((Y+1)) done This almost works, it loops over the species x,y,z and asks for input but it always overwrites x again and again and doesn't move onto the others. I think the problem lies in the sed substitution of a variable for a user defined variable. I would really appreciate any mistakes you might have spotted or any other ways to do this you might think of. Last edited by ce124; 04-13-2007 at 04:36 AM.. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|