zoukankan      html  css  js  c++  java
  • [Linux] 批量把不规则的Android应用程序命名为[中文_版本号](在无中文名称时命名为英文)

    #!/bin/bash - 
    #===============================================================================
    #
    #          FILE: apk_rename.sh
    # 
    #         USAGE: ./apk_rename.sh 
    # 
    #   DESCRIPTION: 
    # 
    #       OPTIONS: ---
    #  REQUIREMENTS: ---
    #          BUGS: ---
    #         NOTES: ---
    #        AUTHOR: linkscue (scue), linkscue@gmail.com
    #       CREATED: 2013年04月15日 15时17分18秒 HKT
    #     COPYRIGHT: Copyright (c) 2013, linkscue
    #      REVISION: 0.1
    #  ORGANIZATION: ATX风雅组
    #===============================================================================
    
    set -o nounset                              # Treat unset variables as an error
    if [[ $# != 1 ]]; then
        echo "usage: $(basename $0) <apk_dir>"
        exit 0
    fi
    dir="$1"
    
    #-------------------------------------------------------------------------------
    #  相关的函数
    #-------------------------------------------------------------------------------
    en_label ()                                     # 获取英文名称
    {
        aapt d badging "$1" | awk -n -F"'" '/application-label:/ {print $2}'| sed 's/ //g' 2>/dev/null
    }
    
    cn_label ()                                     # 获取中文名称
    {
        aapt d badging "$1" | awk -n -F"'" '/application-label-zh_CN/ {print $2}' | sed 's/ //g' 2>/dev/null
    }
    zh_label ()
    {
        aapt d badging "$1" | awk -n -F"'" '/application-label-zh:/ {print $2}' | sed 's/ //g' 2>/dev/null
    }
    version ()
    {
        aapt d badging "$1" | awk -n -F"'" '/versionName/ {print $6}'| sed 's/ //g' 2>/dev/null
    }
    activity ()                                     # 获取活动
    {
        aapt d badging "$1" | awk -n -F"'" '/launchable-activity/ {print $2}' | sed 's/ //g' 2>/dev/null
    }
    
    #-------------------------------------------------------------------------------
    #  变量替换方式把' '替换为'_'
    #-------------------------------------------------------------------------------
    find $dir -name "*.apk" -type f | while read line;            # 只显示文件
        do tmp=\"$line\";                           # 获取文件
        echo $tmp;                                  # 为xargs准备
        echo ${tmp// /_} ;                          # 变量替换 
    done | xargs -n 2 mv -v 2> /dev/null
    
    find $dir -name "*.apk" -type f | while read apk
    do
        version_name=$(version "$apk")
        cn_label_name=$(cn_label "$apk")
        if [[ "$cn_label_name" != "" ]]; then
            new_name="${cn_label_name// /_}"_"$version_name".apk
            echo "mv: $(basename "$apk")   --> $new_name"
            mv "$apk" "$dir/$new_name"
        else
            zh_label_name=$(zh_label "$apk")
            if [[ "$zh_label_name" != "" ]]; then
                new_name="${zh_label_name// /_}"_"$version_name".apk
                echo "mv: $(basename "$apk")   --> $new_name"
                mv "$apk" "$dir/$new_name"
            else
                en_label_name=$(en_label "$apk")
                if [[ "$en_label_name" != "" ]]; then
                    new_name="${en_label_name// /_}"_"$version_name".apk
                    echo "mv: $(basename "$apk")   --> $new_name"
                    mv "$apk" "$dir/$new_name"
                fi
            fi
    
        fi
    done 2> /dev/null

     

    ------------
    微博:http://weibo.com/scue
    Github:http://github.com/scue
  • 相关阅读:
    直接插入排序
    简单选择排序
    xml错误: A pseudo attribute name is expecte
    接口, 抽象类
    The hierarchy of the type AudienceAdvice is inconsistent 《spring in action》
    spring配置文件出错解决办法
    Sangfor tester 实习总结
    求一棵树的面积,2014百度开发测试笔试题
    百度2014校招-深圳-开发测试-求最小“不重复数”
    二个数相加,不使用加减乘除
  • 原文地址:https://www.cnblogs.com/scue/p/3022241.html
Copyright © 2011-2022 走看看