您的位置:首页 > 游戏 > 手游 > 北京最新新闻报道_小程序后台管理系统_什么企业需要网络营销和网络推广_免费发布信息的平台有哪些

北京最新新闻报道_小程序后台管理系统_什么企业需要网络营销和网络推广_免费发布信息的平台有哪些

2025/3/10 21:02:46 来源:https://blog.csdn.net/for_syq/article/details/144031121  浏览:    关键词:北京最新新闻报道_小程序后台管理系统_什么企业需要网络营销和网络推广_免费发布信息的平台有哪些
北京最新新闻报道_小程序后台管理系统_什么企业需要网络营销和网络推广_免费发布信息的平台有哪些

./copy.sh A路径 B路径 文件名 key
./copy.sh A_res B_res strings.xml hello
将A_res文件为strings.xml中的hello,复制到项目B_res文件为strings.xml中

#!/bin/bash# 检查输入的参数数量
if [ "$#" -ne 4 ]; thenecho "用法: $0 <源路径> <目标路径> <目标文件名> <关键字>"exit 1
fi# 获取输入的四个参数oldPath=$1         # 源路径
newPath=$2         # 目标路径
targetFile=$3      # 目标文件名
keyword=$4         # 要查找的关键字# 定义获取字符串中心内容的函数
function getCenter {local one=$1local theLeft=`echo ${one#*\">}`local theCenter=`echo ${theLeft%<\/*}`echo "$theCenter"
}# 定义删除文件末尾多余空行的函数
function deleteBlankRow() {local line=$1local a=`awk '{if($0 != "") {i = 0} else {i++}} END {print i}' $line` # 获取末尾空行数if [ "$a" -ne 0 ]; thenfor ((i=1; i<=a; i++)); dosed -i -e '$ {/^$/d;}' $line # 删除末尾空行donefi
}# 进入源路径并查找指定文件
cd "$oldPath" || exit
find . -name "$targetFile" -type f | cut -c3- > stringList.txt# 定义注释内容
strt="<!--SR: modify by $(whoami) $(date +%Y%m%d) start-->"
endd="<!--SR: modify by $(whoami) $(date +%Y%m%d) end-->"# 循环读取文件列表中的每一行
while read -r line; doss=`grep -wh "$keyword" "$line"`  # 在文件中查找关键字if [ -z "$ss" ]; thencontinuefi# 切换到目标路径cd "$newPath" || exitif [ -e "$line" ]; thenww=`grep -wh "$keyword" "$line"`if [ -z "$ww" ]; then# 如果目标文件中没有关键字内容deleteBlankRow "$line"sed -i '$d' "$line"echo -e "$ss" >> "$line"echo "</resources>" >> "$line"#dos2unix "$line"  # 转换文件格式,去掉 ^Mcd "$oldPath" || exitcontinueelse# 如果目标文件中有关键字内容,比较字符串L=`grep -wn "$keyword" "$line" | cut -d : -f 1`nr=`sed -n "${L}p" "$line"`nrCenter=`getCenter "$nr"`ssCenter=`getCenter "$ss"`if [[ "$ssCenter" == "$nrCenter" ]]; thencd "$oldPath" || exitecho "相等"continueelseecho "不相等"fi# 移植字符串并添加注释theLeft=`echo ${nr%\">*}`kn=`echo "${nr%%<*}" | wc -L`sed -i "${L}d" "$line"ssRight=`echo ${ss#*\">}`ssNew=$theLeft\">$ssRightfor (( j=1; j<$kn; j++ )); dostrt=" ${strt}"endd=" ${endd}"ssNew=" ${ssNew}"donesed -i "${L}i\\ ${ssNew}" "$line"sed -i "${L}i\\ ${strt}" "$line"sed -i "$((L+2))i\\ ${endd}" "$line"#dos2unix "$line"  # 转换文件格式,去掉 ^Mcd "$oldPath" || exitcontinuefielseecho "$line 文件不存在"cd "$oldPath" || exitcontinuefi
done < stringList.txt# 清理临时文件
rm stringList.txt

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com