
ここに置き換える必要があるファイルが何千ものあります。だから私はすべての古い変数を繰り返して新しい変数に置き換えるbashプログラムを作成しようとしています。これが私が現在持っているものです。
たとえば、古い変数と新しい変数の両方を含むファイルがあるため、最初の値を2番目の値に置き換える必要があります。このファイルの名前をnewに指定しました。
web_lgl,web_lgl_index
web_matchmaker,web_matchmaker_index
web_mds,web_mds_index
web_metadata,web_metadata_index
web_mqmon,web_mqmon_index
web_pdconfig,web_pdconfig_index
web_people,web_people_index
web_pescado,web_pescado_index
これで、次のようにwhileループを作成しました。
while IFS="," read old new; do
find . -name "savedsearches.conf" -exec sed "s/$old/$new/g" '{}' \;
done < new
これは実際に動作します。古い値を新しい値に置き換えます。ただし、savesearches.confファイルで次の特定の文字列を置き換えようとします。
index="web_lgl"
index = "web_matchmaker"
index= "web_pdconfig"
ファイル内の任意の文の代わりに
description: web_lgl contains AWS data. which is collected from AWS.
したがって、index = で始まる変数のみをターゲットとして指定し、その文字列の他のすべての項目は無視できるようにbashスクリプトを調整する必要があります。 bashプログラムにindex =を追加しようとしましたが、ヒットを取得できませんでした。たとえば、次のコードはヒットを生成しません。
while IFS="," read old new; do
find . -name "savedsearches.conf" -exec sed "s/index=$old/index=$new/g" '{}' \;
done < new
findコマンドで見つけた任意の文ではなくindex=の後の値を具体的にターゲットに指定するようにbashスクリプトを調整する方法はありますか?
答え1
sedのこの正規表現はで始まる行だけを置き換える必要がありますindex
。
while IFS="," read old new; do
find . -name "savedsearches.conf" -exec sed "/^index/s/index=$old/index=$new/g" '{}' \;
done < new