- #1
ecastro
- 254
- 8
- TL;DR Summary
- How to apply each element of a multi-dimensional array to an SED in Bash script?
I have a .dat file which contains an ##m \times n## (specifically, a ##9 \times 2##) array and I have a file which has this kind of format,
where xx and yy are numbers (I'll call this file the input_file). This file serves as an input to an external program, which I shall insert into a for-loop. So, in every iteration, the input_file will have different values and will be processed by the external program. However, the external program needs to be run in a Bash script, which I am not familiar.
I have known that by simply replacing xx and yy by a string and saving it into a sort of template input_file I could use SED to replace the string by the elements of the .dat file. My currently working example would be:
But I am running through an error in SED saying that I have an unterminated 's'. What am I doing wrong here?
Thank you in advance, and I hope I conveyed my problem clearly.
Bash:
variable_x xx
variable_y yy
I have known that by simply replacing xx and yy by a string and saving it into a sort of template input_file I could use SED to replace the string by the elements of the .dat file. My currently working example would be:
Code:
input=`cat dat_file.dat`
for ((i=0;i<=9;i++)); do
sed "s/xx/${input[$i, 1]}/" -e "s/yy/${input[$i, 2]}/" template_file > input_file
external_program < input_file >> output_file # calls the external program and returns the output file
done
But I am running through an error in SED saying that I have an unterminated 's'. What am I doing wrong here?
Thank you in advance, and I hope I conveyed my problem clearly.