Script overlays a large number of text files into a file

Source: Internet
Author: User
This script is intended for TXT files that need to be merged in the current directory, not in the current directory, and the TXT file name is numerically named, and the script moves the source file to the/tmp directory
#!/bin/bash#创建备份文件路径BAK-DIR=`/tmp/txt-bak-`date +%F``mkdir $BAK-DIR#查找当前路径下所有后缀名为.txt的文件并统计数量FILE_COUNT=`find . -type f -name "*.txt"  |wc -l`#判断当前路径下是否还有超过10个txt文件需要合并while [ $FILE_COUNT -gt 10 ]do    #查找当前路径下所有后缀名为.txt的文件并排序,取出前10个文件名    for i in `find . -type f -name "*.txt" |awk -F/ ‘{print $2}‘| sort -h |head -10`    do         #合并10个文件        cat tmp.log $i >>final.log        #删除已合并文件        mv $i  $BAK-DIR    done    #重新统计当前目录下txt文件数量    FILE_COUNT=`find . -type f -name "*.txt"  |wc -l`done

Script overlays a large number of text files into a file

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: 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.