I need change price the HTML file, which search and store them in array but I have to change and save /nuevo-focus.html
price=( `cat /home/delkav/info-sitioweb/html/productos/autos/nuevo-focus.html | grep -oiE '([$][0-9.]{1,7})'|tr '\n' ' '` )
price2=( $90.880 $0 $920 $925 $930 $910 $800 $712 $27.220 $962 )
sub (){
for item in "${price[@]}"; do
for x in ${price2[@]}; do
sed s/$item/$x/g > /home/delkav/info-sitioweb/html/productos/autos/nuevo-focus.html
done
done
}
sub
Output the “cat /home/…/nuevo-focus.html|grep -oiE ‘([$][0-9.]{1,7})’|tr ‘\n’ ‘ ‘` )” is…
$86.880 $0 $912 $908 $902 $897 $882 $812 $25.725 $715
In
bashthe variables$0through$9refer to the respective command line arguments of the script being run. In the line:They will be expanded to either empty strings or the command line arguments that you gave the script.
Try doing this instead:
EDIT for part two of question
If what you are trying to do with the
sedline is replace the prices in the file, overwriting the old ones, then you should do this:This will perform the substitution in place (
-i), modifying the input file.EDIT for part three of the question
I just realized that your nested loop does not really make sense. I am assuming that what you want to do is replace each price from
pricewith the corresponding price inprice2If that is the case, then you should use a single loop, looping over the indices of the array:
I’m not able to test that right now, but I think it should accomplish what you want.
To explain it a bit:
${!price[*]}gives you all of the indices of your array (e.g.0 1 2 3 4 ...)For each index we then replace the corresponding old price with the new one. There is no need for a nested loop as you have done. When you execute that, what you are Basically doing is this: