私が望むのは、xmlファイルを編集してタグの1つの内容を置き換えることです。これは私のスクリプトです。
while read line; do
if [[ "$line" == *"<Valuec=\"0\">"* ]]
then
~/bin/nn4 Decrypt1 "$line" | sed 's/^/\<Valuec=\"0\"\>/g;s/$/\<\/Valuec\>/g'
fi
done <"$1"
nn4
タグを削除し、コンテンツの復号化を行い、sed
タグを再配置するように指示します。
これは入力です
<string>
<Id>1</Id>
<file>file.txt</file>
<Valuec="0">982498as9adhfsdf</Valuec>
</string>
<string>
<Id>2</Id>
<strStringCaption>file2.txt</strStringCaption>
<Valuec="0">2389aHASDasd</Valuec>
</string>
しかし、もちろんこれは編集された行だけを出力します。次のようになります。
<Valuec="0">decryptedstring</Valuec>
<Valuec="0">decryptedstring2</Valuec>
しかし、私は次のように見えたいです。
<string>
<Id>1</Id>
<file>file.txt</file>
<Valuec="0">decryptedstring</Valuec>
</string>
<string>
<Id>2</Id>
<strStringCaption>file2.txt</strStringCaption>
<Valuec="0">decryptedstring2</Valuec>
</string>
ベストアンサー1
else
ループ本体の内部に条件を追加するだけですwhile
。
while IFS= read -r line; do
if [[ "$line" == *"<Valuec=\"0\">"* ]]
then
~/bin/nn4 Decrypt1 "$line" | sed 's/^/\<Valuec=\"0\"\>/g;s/$/\<\/Valuec\>/g'
else
printf '%s\n' "$line"
fi
done <"$1"
使用に注意してくださいIFS= read -r
全読ワイヤー。
それにもかかわらず、この作業には他のツールを使用することを検討する必要があります。シェルスクリプトでwhileループを使用することは悪い習慣と見なされます。。