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

功能:

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

使用场景:

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

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

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

#!/bin/bash
echo "################################################### README INFO ##############################################################"
echo "### Purpose: Combin files                                                                                                  ###"
echo "### Made By: PomanTeng                                                                                                     ###"
echo "### E-mail: [email protected]                                                                                       ###"
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 !

你可能感兴趣的:(shell,运维,云计算)