特定のファイルにこのような入力があります
#- seeds: "12.123.233.213,123.231.3.2"
- seeds: "12.12.21.21,43.435.54.54"
ご覧のとおり、シードには 2 つの連続した IP アドレスが含まれているため、ファイル内のその IP アドレスを変更したいと考えています。1 行目は「#」で始まるため考慮されません
これを行うために、私はこれを持っています:
val=' - seeds: "'
newSeed=${val}${ip1}','${ip2}'"' # ---> I'm creating the new seed
str=`grep "\s- seed" $file` # ---> finding matching character
echo $str # ---> it does print out the 2nd line
sed -i 's|${str}|${newSeed}|g' $file # --> now replace the matched string with new seed value
ただし、ファイル内の値は置き換えられません。ここで何が間違っていますか?