• 合并两个文件为一个文件并转换文件字符格式


    功能:

    把两个文本文件合并成一个文本文件,并转化合并后文件的Linux字符格式为Windows字符格式

    使用场景:

    需要把两个文件整个粘贴成一个文件并制作成报表。

    比如一个文件中存储了文件名,另一个文件中存储了文件内容,包着两个文件毡贴起来就得到了每个文件名所对应的内容的两列报表。

    **************************************************************************************************************

    #!/bin/bash
    echo "################################################### README INFO ##############################################################"
    echo "### Purpose: Combin files                                                                                                  ###"
    echo "### Made By: PomanTeng                                                                                                     ###"
    echo "### E-mail: denggongmengbo@gmail.com                                                                                       ###"
    echo "### WeChat: 1807479153                                                                                                     ###"
    echo "### Version Identification Number:V2.1.0                                                                                   ###"
    echo "### Procedure Identification Number:20230916                                                                               ###"
    echo "##############################################################################################################################"

    # Check the current OS user

    [[ $(id -u) -gt 0 ]] && echo "请用root用户执行此脚本!" && exit 1

    source /etc/profile

    source ~/.bash_profile

    echo "     "
    echo -e "现在时刻 :\n \n $(date)"
    echo "     "

    echo "     "
    echo "当前OS及其依托的基础设备类型 :"
    echo "     "
    cat /etc/*release* | awk '/release/' | uniq
    echo "     "
    hostnamectl | awk '/Chassis|Virtualization/'
    echo "     "

    # Creat the combin file, which is ".xls" file

    touch combin.xls && chmod 777 combin.xls


    # Get the name-Content-List : read  a line from source file and write 

    find /working/ -name "*txt*" -exec ls -F {} \; | while read line

                           do

                               cat ${line} | sed -n '8p' | awk -F "]" '{print $2}' >> /working/wenzi.txt

                               cat ${line} | sed -n '2p' | awk '{print $NF}' | awk -F "/" '{print $4}' | sed 's@.\{5\}$@@' >> /working/yinpin.txt

                           done


    # Inert a title into the combin file

    sed -i '1i\内容' /working/wenzi.txt

    sed -i '1i\文件名' /working/yinpin.txt

    # Get the combin-Report

    paste /working/yinpin.txt /working/wenzi.txt > /working/combin.xls

    # Convert UTF-8 to ANSI

    iconv -f utf8 -t gb2312 /working/combin.xls -o /working/combin2dos.xls

    # Transfer the file for downloading

    cp /working/combin2dos.xls /home/Downlods/

    chmod 777 /home/Downlods/combin2dos.xls

    # The End !

  • 相关阅读:
    Windows 同步时间服务器批处理
    全网首发 黑马高端课程,仅限老学员免费领取
    [MyBatisPlus]DQL编程控制①(条件查询)
    文字悬停效果
    Python多方法高效匹配、关联操作两个列表
    Go函数介绍与一等公民
    [linux]信号处理:信号编码、基本API、自定义函数和集合操作的详解
    【Python基础】if __name__ == ‘__main__‘:和assert函数
    【antd vue pro】设置项目默认语言为中文:
    基于Mongodb分布式锁简单实现,解决定时任务并发执行问题
  • 原文地址:https://blog.csdn.net/UsamaBinLaden6976498/article/details/132917517