求大神解决一下这个shell里文本分行的方法
Tofloor
poster avatar
luke
deepin
2017-01-26 07:02
Author


如题,如图,我在shell用less显示了一个txt文本文件,文本文件是有一个一个词组成的。
我现在想把文本排版成一个词一行,比如“研究”一行,下一行是“法”,以此类推。
我以前用的方法是less txt| awk '{print $1 "\t"print $2 “\t”print$3……}' 这样的方法。可以做到但是实在是太麻烦了,一点都不高效。求一种更加渐变的分行方法。欢迎讨论
Reply Favorite View the author
All Replies
avatar
luke
deepin
2017-01-26 07:03
#1
错了错了 上面的命令应该是less txt| awk '{print $1 "\n"print $2 “\n”print$3……}'
Reply View the author
avatar
luke
deepin
2017-01-26 18:19
#2
求大神啊啊啊啊啊啊啊啊!!!!!!!!!!!!!!!!!!
Reply View the author
avatar
a62229776
deepin
2017-01-26 22:28
#3
tr命令,替换空格为换行符。tr '\t' '\n'
Reply View the author
avatar
a62229776
deepin
2017-01-26 22:33
#4
https://bbs.deepin.org/post/134499
tr命令,替换空格为换行符。tr '\t' '\n'

cat txt | tr '\t' '\n'
Reply View the author
avatar
ghou
deepin
2017-01-26 23:07
#5
awk '{ for (i = 1; i <= 10; i++) print $i }' test.txt

awk '{ for (i = 1; i <= 10; i++) printf "%s \n",$i }' test.txt

不知道这算不算符合楼主要求
Reply View the author
avatar
luke
deepin
2017-02-06 04:33
#6
https://bbs.deepin.org/post/134499
tr命令,替换空格为换行符。tr '\t' '\n'

老哥 稳!你这方法算是最简单了!
Reply View the author
avatar
luke
deepin
2017-02-06 04:37
#7

符合!也是不错的思路!
Reply View the author
avatar
ghou
deepin
2017-02-17 23:46
#8
发现一个不错的文本格式化命令 fmt

Reply View the author
avatar
sinux
deepin
2017-02-18 00:51
#9
tr和fmt是最方便的
然而还是分享一个奇技淫巧
for i in `cat txt`;do echo $i ;done

Reply View the author
avatar
luke
deepin
2017-02-21 08:26
#10
https://bbs.deepin.org/post/134499
发现一个不错的文本格式化命令 fmt

我去 可以!
Reply View the author
avatar
luke
deepin
2017-02-21 08:28
#11
https://bbs.deepin.org/post/134499
tr和fmt是最方便的
然而还是分享一个奇技淫巧
for i in `cat txt`;do echo $i ;done

这个我也用过
Reply View the author