I have an HTML file that lays out images of text to create interesting typographic patterns. The images are placed in the local web page with
<img src="[path-to-project-folder]/DIR/[filename].png">.
The project folder has 15 folders with variations of all the images in them, named 001, 002 etc. I want to replace DIR with a random number from 001-015 and have tried the following in a shell script to get sed to replace the variable number in steps across my source file;
for RUN in {1..15};
do
var1=`shuf -i 001-015 -n 1`
step=$((step + 1));
while [ ${#var1} -ne 3 ];
do
var1="0"$var1
done
echo $var1
echo $step
sed -i -e "s/DIR/$var1/"{100..1..$step} temp.htm
done
Unfortunately that results in an error of
sed: -e expression #1, char 11: unknown option to `s'
I know from attempting to debug that $var1 is replaced okay. It is $step that is not getting through. I have tried things like ${step} and combinations of backslashes but that’s just copying other scripts that work rather than truly understanding what is going on after my sed s/// argument to explain the error. The expansion section in the bash manual doesn’t seem to explain the sed error.
Can anyone help please? I’d like the output to be random like
<img src="[path-to-project-folder]/001/[filename].png"><img src="[path-to-project-folder]/014/[filename].png"><img src="[path-to-project-folder]/003/[filename].png">.
and so on. I’m using sed 4.4 on Ubuntu 18.10 with bash 4.4.20
James Davies is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.