Shell Traversal Directory Bulk extract file name containing a string and a specific suffix

Source: Internet
Author: User

#!/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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.