zoukankan      html  css  js  c++  java
  • shell 搜索指定目录下所有 jar 文件生成csv文件

    虽说比较简单,但希望分享给大家。按需求改成想找的:例如txt,xls 等。

    脚本名 扫描的路径 文件名

    testFind.sh /  testFind.txt (如果未配置环境变量  ./testFind.sh /  testFind.txt 或sh 启动) 

    function find(){
    for file in `ls $1`
    do
        if [ -d $1"/"$file ]
        then
            e $1"/"$file $2
        else
             # echo -e $1"/"$file"
    " -> ${contentFile}"/"search_test.txt
            # if [ -e $1"/"$file ];then
            #      echo $1/$file
            #      echo ""
            #      echo $1"/"$file >> ${contentFile}/search_test.txt
                  # echo "${file}" -> $contentFile/search_test.txt
            # fi
             if [[ ${file} =~ "."  ]];then
    
                  if [ "${file##*.}"x = "jar"x ];then
                      sub=${file%.*}
                     # sedStr=${sub//-/_}
                      version=${sub##*-}
                      name=${sub%-*}
                     # echo "${name}" 
                      if [[ $version == [0-9]* ]];then
                # csv文件是以“,”分割的文件,所以拼逗号 
                          echo "$sysname","${name}","$version","${file}","$1",""  >> $contentFile/$sysname.csv
                      else
                          echo "$sysname","${name}",,"${file}","$1","" >> $contentFile/$sysname.csv
                      fi    
                  fi
         fi
        fi
    done
    }
    
    ###########################main####################
    if [ $# -lt 2 ]
        then echo '请输入2个参数:[目标文件夹路径] , [系统英文名称] '
        exit 3
    fi
    
    echo " "
    echo "当前查询路径: $1"
    echo " "
    
    #当前执行的路径
    contentFile=`pwd`
    #文件名 我们是按照系统统计的所以命名这个
    sysname=$2
    #判断文件是否存在
    if [ -e $contentFile/$sysname.csv ];then
       rm -r $contentFile/$sysname.csv
    fi
    
    echo ""
    echo "[开始]搜索所有 *jar* 文件---- "
    echo ""
    
    
    find $1 $2
    
    echo "[结束] 清查看jar文件清单:$contentFile/$2.csv"
    echo ""
    exit 0

    --结果这样的

  • 相关阅读:
    16年青岛网络赛 1001 I Count Two Three
    最短路算法--模板
    POJ 1511 Invitation Cards (spfa的邻接表)
    POJ 2240 Arbitrage
    POJ 1502 MPI Maelstrom
    POJ 1860 Currency Exchange (最短路)
    最短路径--SPFA 算法
    POJ 3660 Cow Contest
    POJ 3259 Wormholes (Bellman_ford算法)
    POJ 3268 Silver Cow Party (双向dijkstra)
  • 原文地址:https://www.cnblogs.com/itlixian/p/11310882.html
Copyright © 2011-2022 走看看