#!/bin/shmkdir /home/zhengyk/desktop/tmp #创建临时文件夹, used to store the extracted files #mkdir /home/ zhengyk/desktop/local #创建临时文件夹, used to store filter results List_alldir () { for file in $ 1/*doif [ -d $file ]; thenlist_alldir $fileelsefilename =${file##*/} # Remove the filename and suffix from the path echo "$filename" if [[ ' echo $filename | awk -f '. ' ' $0~/.*123.*zip/{print $3} ' = ' Zip ' ]] # ' 123 ' as a substring in the filename # elif [[ ' echo $file | awk -f '. ' ' $0~/.*123.*zip/{print ${file##*.}} ' ' = Zip ' ]]then#tar jxf $file -C /home/zhengyk/Desktop/tmp #解压文件dddunzip -o $file -d /home/zhengyk/Desktop/tmp #解压文件 # grep_word /home/zhengyk/desktop/tmp #执行过滤关键字的函数 #rm -rf /home/zhengyk/ Desktop/tmp/* #清理现场, ready to unzip the next file! echo "$file ..........ok!" #显示被处理的bz2文件! Fifidone}grep_word () {for fileb in $1/*doif [ -f $fileb ]; then# " Bkeep "is the keyword you want to filter, according to the actual, self-setting grep -h " T " $fileb >> /home/zhengyk/desktop/tmp.txt #H Display the file name in the results so we could read it! elsegrep_word $filebfidone}if [ $# -gt 0 ]thenlist_alldir "$" elseecho "Please input:./list_alldir.sh dirpath" fi
Reference Link: http://www.360doc.com/content/10/0928/16/3234041_57087955.shtml
This article is from the "Cabbage" blog, please be sure to keep this source http://dreamylights.blog.51cto.com/1163218/1755231
Shell Traversal Directory Bulk extract file name containing a string and a specific suffix