使用shell命令怎么实现将当前目录下多个文件合并为一个文件

这期内容当中小编将会给大家带来有关使用shell命令怎么实现将当前目录下多个文件合并为一个文件,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

1、将多个文件合并为一个文件没有添加换行符

find ./ -name "iptv_authenticate_201801*" | xargs cat > iptv_authenticate.txt

2、设置换行符^J

find ./ -name "iptv_authenticate_201801*" | xargs sed 'a\^J' > iptv_authenticate.txt

3、默认换行符

find ./ -name "iptv_authenticate_201801*" | xargs sed 'a\' > iptv_authenticate.txt

find ./ -name "iptv_liveswitch_201801*" | xargs sed 'a\' > iptv_liveswitch.txt

find ./ -name "iptv_qualified_201801*" | xargs sed 'a\' > iptv_qualified.txt

find ./ -name "iptv_vodload_201801*" | xargs sed 'a\' > iptv_vodload.txt

当前目录下所有后缀为txt文件中追加一行数据作为文件内容的第一行内容

1、方法一

for fullpath in `find . -type f -name "*.txt"`
do
  sed -i '1i\Num\tPhone\tDate\tMessage\tId\tGudge' ${fullpath}
done

备注:

-type  f 是指后边的查找文件类型为文件

2、方法二

find . -type f -name "*.txt" | xargs -I {} sed -i '1i\Num\tPhone\tDate\tMessage\tId\tGudge' {}

上述就是小编为大家分享的使用shell命令怎么实现将当前目录下多个文件合并为一个文件了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。