#!/bin/bash
#脚本用途 替换所有json文件(main.json 除外)中的 ios下载链接
#调用格式 "xxx.sh" (脚本名称) "ios||and" (参数1) "https:xxxx" (参数2)
#调用示例 *sh and https:andxxxxx.apk
#调用示例 *sh ios https:andxxxxx.ios
#执行时 会备份源文件到当前目录bak_json下
cd "$(dirname $0)"
pwd
json_remove="main.json" #替换排除文件
#json_files=$(find . -maxdepth 1 -name "*.json" ! -name ${json_remove})
#find 查找会存在文件名为./影响文件备份
if [ "$1" == "ios" -o "$1" == "and" ] && [ "$2" != "" ]; then
for js_file in $(ls | grep .*json | grep -v ${json_remove}); do
if [ -f ${js_file} ]; then
if [ "$1" == "ios" ]; then
old_url=$(grep -oP ios.*?http.*?\" ${js_file} | awk -F[\"] '{print $3}')
else
old_url=$(grep -oP and.*?http.*apk.*?\" ${js_file} | awk -F[\"] '{print $3}')
fi
now_url=$2
if [ "$old_url" != "" ]; then
#开始备份
mkdir -p bak_json && cp ${js_file} bak_json/$(date +"%F")-${js_file}
#开始替换
sed -i "s#$old_url#$now_url#g" ${js_file}
echo "替换文件 ${js_file} 中 $old_url 为 $now_url"
else
echo "没有匹配到旧的url 文件: ${js_file}"
fi
fi
done
else
echo "格式 \"xxx.sh\" (脚本名称) \"ios||and\" (参数1) \"https:xxxx\" (参数2)"
fi
shell脚本 -- 用途替换所有json文件(main.json 除外)中的 ios下载链接
最新推荐文章于 2024-06-04 14:50:20 发布