1

これは私が編集しようとしているxmlファイルです

<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<boolean name="public_checkins" value="false" />
<string name="checkins">[{&quot;storeName&quot;:&quot;Rundle Street&quot;,&quot;prize&quot;:&quot;price_fwh&quot;,&quot;checkinTime&quot;:1352717951195,&quot;prizeClaimed&quot;:false,&quot;storeId&quot;:57,&quot;expired&quot;:false},{&quot;storeName&quot;:&quot; Street&quot;,&quot;prize&quot;:&quot;price_fmf&quot;,&quot;checkinTime&quot;:1352717723886,&quot;prizeClaimed&quot;:false,&quot;storeId&quot;:57,&quot;expired&quot;:false}]</string>
*<string name="uuid">30212345-0c1e-dcb-974e-5effa7f016be</string>*
</map>

文字列uuidを編集し、スクリプトを実行するたびにuuidをランダムに生成された一連の数字に置き換えるシェルスクリプトを作成しようとしています。

以下は私が思いついたスクリプトです。

#!/system/bin/sh

set number=$RANDOM

echo "<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<boolean name="public_checkins" value="false" />
<string name="checkins">[{&quot;storeName&quot;:&quot; Street&quot;,&quot;prize&quot;:&quot;price_fwh&quot;,&quot;checkinTime&quot;:1352717951195,&quot;prizeClaimed&quot;:false,&quot;storeId&quot;:57,&quot;expired&quot;:false},{&quot;storeName&quot;:&quot;Rundle Street&quot;,&quot;prize&quot;:&quot;price_fmf&quot;,&quot;checkinTime&quot;:1352717723886,&quot;prizeClaimed&quot;:false,&quot;storeId&quot;:57,&quot;expired&quot;:false}]</string>
<string name="uuid">302$number-0c1e-dcb-974e-5effa7f016be</string>
</map>
" > /data/data/com.app/shared_prefs/app.xml
4

2 に答える 2

0
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
<string name="uuid">302%1$s-0c1e-dcb-974e-5effa7f016be</string>
</map>

この形式を使用して、以下のような文字列を取得できます

String uuid = String.format(getResources().getString(R.string.uuid), YourUUIDNumber);

完全な文字列を受け取ります

302xxxxxx-0c1e-dcb-974e-5effa7f016be

xxxxxxx は、文字列の format メソッドで渡した値です。

于 2012-11-13T08:49:59.087 に答える
0

これにはPerlの方が適しています

file=/data/data/com.app/shared_prefs/app.xml
mv $file $file.bak
{
 arr=({0..9} {a..f})
 while IFS=\> read -d\< tag str; do
  if [[ $tag = *'name="uuid"'* ]]; then
   randomstr=
   for ((i=0;i<32;i++)); do
    if ((i%4==0 && i/4>=2 && i/4<6)); then
     randomstr=$randomstr-
    fi
    randomstr=$randomstr${arr[RANDOM%16]}
   done
  printf "%s" "$tag${str:+>}$randomstr<"
  else
   printf "%s" "$tag${str:+>}$str<"
  fi
 done
 printf "%s\n" "$tag>"
} <$file.bak >$file
# rm $file.bak #
于 2012-11-13T09:06:13.887 に答える