将文本文件目录组合成CSV,每行一个文件

pro*_*ian 1 bash

我有一个大型的文本文件目录,每个目录都很复杂:

说file1.txt:

依靠相信而不是倾听.足够周围去除巴顿同意后悔或它.可以估计的优点是命令提供.今年拍得很好,现在已经过了.挫败站起来嫁给他了.做相关的先生帐户brandon up.从来没有准备好的火腿错了这些诙谐的他.我们的指南针看到年龄不文明的天气禁止她的分钟.准备如何,但真正的儿子新.

他在有利的情况下对比增长,他认为是惊人的.仿佛被拍成一团.通过它足以让山谷渴望做到.主要的伟大的女仆这些火腿匹配她.Abode尝试做女佣.令人怀疑的处置恢复为dashwood而欢欣鼓舞.

和file2.txt:

在做庄园的人中间.是否庆祝它同情考虑.五月欣喜若狂,确实让这个无知的年龄感到惊喜.她最后一次拥有她的小姐.如果他的处理时间过长,那就太多了.怎么,但是儿子们的女士们.她特别令人不愉快的改变继续毫无保留的解决方案.因此希望中国充满希望.它是否认为楼梯分支可以承受三十分钟.

盲目相等,而先生风格.Lain领导,事实没有.一个喜欢解决幸福的运动员继续.高声丰富的真实.哦传达他的直接尖锐.同样欢迎她设置没有任何重力是否派对.肥沃的假设害羞指向坚持尊重.

我需要做的是创建一个新文件,比如allfiles.txt:

Am no an listening depending up believing. Enough around remove to barton agreed regret in or it. Advantage mr estimable be commanded provision. Year well shot deny shew come now had. Shall downs stand marry taken his for out. Do related mr account brandon an up. Wrong for never ready ham these witty him. Our compass see age uncivil matters weather forbade her minutes. Ready how but truth son new under. Am increasing at contrasted in favourable he considered astonished. As if made held in an shot. By it enough to valley desire do. Mrs chief great maids these which are ham match she. Abode to tried do thing maids. Doubtful disposed returned rejoiced to dashwood is so up. 

Among going manor who did. Do ye is celebrated it sympathize considered. May ecstatic did surprise elegance the ignorant age. Own her miss cold last. It so numerous if he outlived disposal. How but sons mrs lady when. Her especially are unpleasant out alteration continuing unreserved resolution. Hence hopes noisy may china fully and. Am it regard stairs branch thirty length afford. Blind would equal while oh mr do style. Lain led and fact none. One preferred sportsmen resolving the happiness continued. High at of in loud rich true. Oh conveying do immediate acuteness in he. Equally welcome her set nothing has gravity whether parties. Fertile suppose shyness mr up pointed in staying on respect. 
Run Code Online (Sandbox Code Playgroud)

在这种情况下,此文件只有两行,每行都有完整的文本.我搜索了档案,但似乎无法在bash中找到这方面的实现.

Bar*_*mar 5

for file in dir/* #Process all files in directory
do
   tr '\n' ' ' < "$file" # Remove newlines
   echo ''   # Add newline between files
done > newfile # Write all the output of the loop to the newfile
Run Code Online (Sandbox Code Playgroud)


zmo*_*zmo 5

touch allfiles.txt # create allfiles.txt
for f in *.txt; do # for each file of the current directory
    cat "$f" | tr '\n' ' ' >> allfiles.txt; # append the content of that file to allfiles.txt
    echo >> allfiles.txt # insert a new line
done
Run Code Online (Sandbox Code Playgroud)