I'm trying to make a bash shell script that will allow a user to modify another file based on input they give. Maybe someone can see what I'm doing wrong here. I'm still pretty new at this...
Let's say my temp file contains this:
0 1 HELLO 3 4
And here's the code:
old=(0 1 3 4)
new=(zero one two three four five)
cat temp | for i in ${old[@]}; do sed "s=$i=${new[$i]}=g"; let i++; done
The output would then be redirected to a new file. The problem is, that only the first sed is ever applied. For instance, if I change the last command to allow it to echo $i:
cat temp | for i in ${old[@]}; do echo $i; sed "s=$i=${new[$i]}=g"; let i++; done
then the output looks like this:
0
zero 1 HELLO 3 4
1
3
4
The reason I'm trying to do a for/while loop instead of simply piping to sed each time, is that the 'new' array is populated by user input, and can have as many or few elements as the user desires. Any help would be appreciated.