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 '1iNumtPhonetDatetMessagetIdtGudge' ${fullpath}
done

备注:

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

2、方法二

find . -type f -name "*.txt" | xargs -I {} sed -i '1iNumtPhonetDatetMessagetIdtGudge' {}

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对来客网的支持。如果你想了解更多相关内容请查看下面相关链接