首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将文本文件目录合并到CSV中,每行一个文件

将文本文件目录合并到CSV中,每行一个文件
EN

Stack Overflow用户
提问于 2013-06-25 19:33:45
回答 8查看 419关注 0票数 1

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

例如file1.txt:

我不是一个依靠信任的倾听者。已经够多了,巴顿同意了,还是后悔吧。优胜先生,可资估价,奉命供应。一年一炮否认了现在已经有了。会因为他的失败而娶他。做与布兰登先生有关的事。错了,因为从来没有准备好让这些机智的他受骗。我们的指南针看到了年龄,不文明的事情,天气阻止了她的发言。准备如何而真相儿子新下。 他认为,我在有利的情况下越来越吃惊。就像被拍成一张照片一样。它足以满足山谷的欲望。酋长夫人,这些都是火腿配她的。居处试着做女佣的事。可疑的处置,返回,欢欣鼓舞地对达什伍德是如此的兴奋。

和file2.txt:

是谁干的。你们是受人尊敬的吗?这是同情的考虑。五月的欣喜若狂,令无知的时代的优雅感到惊讶。最后拥有她的冷酷小姐。如果他的寿命比处置时间长得多的话。可是儿子夫人夫人什么时候。尤其是她令人不快的改变,继续毫无保留的决心。因此,希望喧闹的中国可以充分和。作为楼梯支行三十长可以负担。 瞎子等于,哦,do先生的风格。兰恩领导,但事实却没有。一位更喜欢的运动员继续着解决幸福的问题。高高在上的,富有的,真实的。哦,传达在他身上做的立即尖锐。同样欢迎她的套装,没有什么是严肃的,无论是派对。富丽堂皇的羞怯先生指的是保持尊敬。

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

代码语言:javascript
复制
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. 

这个文件在本例中只是两行,每一行都是全文。我已经搜索了档案,但似乎找不到实现在bash。

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2013-06-25 19:41:19

代码语言:javascript
复制
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
票数 5
EN

Stack Overflow用户

发布于 2013-06-25 19:41:10

代码语言:javascript
复制
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
票数 5
EN

Stack Overflow用户

发布于 2013-06-25 23:18:02

这里有一个纯中介实现,不需要bashtrcat

代码语言:javascript
复制
        PLEASE DO ,1 <- #1
        DO .4 <- #0
        DO .5 <- #0
        DO COME FROM (30)
        PLEASE ABSTAIN FROM (40)
        DO WRITE IN ,1
        DO .1 <- ,1SUB#1
        DO (10) NEXT
        PLEASE GIVE UP
(20)    PLEASE RESUME '?.1$#256'~'#256$#256'
(10)    DO (20) NEXT
        DO FORGET #1
        PLEASE DO .2 <- .4
        DO (1000) NEXT
        DO .4 <- .3~#255
        PLEASE DO .3 <- !3~#15'$!3~#240'
        DO .3 <- !3~#15'$!3~#240'
        DO .2 <- !3~#15'$!3~#240'
        PLEASE DO .1 <- .5
        DO (1010) NEXT
        DO .5 <- .2
        DO ,1SUB#1 <- .3
(30)    PLEASE READ OUT ,1
        PLEASE NOTE: having had pressing business at the local pub
(40)    the author got bored with this implementation
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17305953

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档