标签:tmp shell 词条 words echo bbl file cat 对比
需求:找出当前开发分支里未上传到词条平台的词条
#! /bin/bash #-----------------------------------------------------------------------# # 手动版说明: # 1、将此shell放在项目根目录里跟.git目录平级; # 2、如果查找的分支显示没有修改,有可能是已经合到master了,所以没有差异; # 3、如果想自己查找某个目录里的所有词条,直接在相应目录执行 grep "\bt('[^']\+'" -ro .| awk -F "'" '{print $2}' | sort -u #-----------------------------------------------------------------------# # 对应平台的标识 aaa 3 bbb 7 ccc 60 # aaa | bbb | ccc projectName=$(git remote -v |head -n 1 | awk '{print $2}' | sed 's/.*\///'| sed 's/\.git//') case $projectName in "aaa") npid=3; ;; "bbb") npid=7; ;; "ccc") npid=60; ;; "exit") echo "异常:未知项目~"; exit ;; esac echo "当前项目:$projectName" # 输入查找的分支 read -p '请输入你所要查找的分支名:' branch [ -z "$branch" ] && echo '异常:未输入分支名~' && exit; # 获取系统最新版本 latestVersionRps=$(curl "https://xxxxxx?npid=${npid}") function parseField() { intercept=`echo ${latestVersionRps#*\"$1\"\:}` fieldValue=`echo ${intercept%%\,*}` } parseField "version" if [ ! -f /tmp/bbl_version ] || [ ! -s /tmp/bbl_version ] || [ `cat /tmp/bbl_version` != $fieldValue ] then # 保存最新版本号 echo $fieldValue > /tmp/bbl_version; bblVersion=$(cat /tmp/bbl_version | awk -F '"' '{print $2}') # 保存所有词条 curl "https://xxxxxx/${npid}/${bblVersion}/CN.json" --compressed | grep -Eo \"CN\"\:\".*?[^\"]\"\, | awk -F '"' '{print $4}' > "/tmp/tmp_all_words_on_bbl_file" fi; if [ -f "/tmp/tmp_all_words_on_bbl_file" ] then cat /dev/null > "/tmp/tmp_modified_files"; cat /dev/null > "/tmp/tmp_words_file"; cat /dev/null > "/tmp/tmp_uniq_words_file"; if git rev-parse --verify $branch || git rev-parse --verify origin/$branch; then git fetch; git checkout $branch || ! echo '异常:切换分支报错,请先暂存当前分支更改~' || exit git pull; git diff --name-only master...$branch > "/tmp/tmp_modified_files"; for file in $(awk '{print $1}' "/tmp/tmp_modified_files") do [ -f "$file" ] && grep "\bt('[^']\+'" -ro "$file"| awk -F "'" '{print $2}' | sort -u >> "/tmp/tmp_words_file"; done cat "/tmp/tmp_words_file" | sort -u > "/tmp/tmp_uniq_words_file" ; else echo "异常:没找到该分支~"; exit; fi; # 如果词条文件内容不为空 if [ -s "/tmp/tmp_uniq_words_file" ] then uniqWordsList=($(cat "/tmp/tmp_uniq_words_file")) allWordsOnBblList=($(cat "/tmp/tmp_all_words_on_bbl_file")) cat /dev/null > "/tmp/tmp_need_upload_words_list"; declare -a needUploadWordsList index=0 isExist=0; for uniqWordsListItem in "${uniqWordsList[@]}" do for allWordsOnBblListItem in "${allWordsOnBblList[@]}" do if [ "${uniqWordsListItem}" == "${allWordsOnBblListItem}" ]; then isExist=1 break fi done if [[ $isExist -eq 0 ]]; then needUploadWordsList[index]=$uniqWordsListItem echo $uniqWordsListItem >> /tmp/tmp_need_upload_words_list index=$((index+1)) else isExist=0 fi done if [ ${#needUploadWordsList[@]} -gt 0 ]; then result=$(cat "/tmp/tmp_need_upload_words_list") echo -e "\033[1;31m\n\n最终需要上传到bbl的词条汇总:\033[0m\n\033[33m$result\033[0m"; else echo -e "\033[1;32m\n\nbbl平台上已存在该分支改动涉及的所有词条\033[0m" fi; else echo "异常:该分支没有修改~"; exit; fi fi;
标签:tmp,shell,词条,words,echo,bbl,file,cat,对比 来源: https://www.cnblogs.com/leyi/p/16435993.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。