Q
從文件中提取單詞
2
A
回答
5
tr命令可以做到這一點...
tr [:blank:] '\n' < test.txt
此詢問tr
程序來代替白色有新線的空間。 輸出爲標準輸出,但它可能會被重定向到另一個文件,的Result.txt:
tr [:blank:] '\n' <test.txt> result.txt
0
以上回答不處理多個空格和這樣的非常好。替代方案是
perl -p -e '$_ = join("\n",split);' test.txt
哪會。例如。
[email protected]:~/ange/linova/build master $ echo "test test" | tr [:blank:] '\n'
test
test
但
[email protected]:~/ange/linova/build master $ echo "test test" | perl -p -e '$_ = join("\n",split);'
test
test
0
這可能會爲你工作:
# echo -e "this is\tmy\nsample text" | sed 's/\s\+/\n/g'
this
is
my
sample
text
0
Perl的答案是:
pearl.214> cat file1
a b c d e f pearl.215> perl -p -e 's/ /\n/g' file1
a
b
c
d
e
f
pearl.216>
1
而這裏明顯的bash行:
for i in $(< test.txt)
do
printf '%s\n' "$i"
done
編輯更短:
printf '%s\n' $(< test.txt)
這一切就是這麼簡單,沒有什麼特別的(可憐)案件包括(和處理多個後續單詞分隔/前/後分離是做正確的事(TM值))。您可以使用$ IFS變量調整字詞分隔符的概念,請參閱bash手冊。
相關問題
- 1. 從文件中提取單詞
- 2. 從文本中提取特定單詞
- 3. 如何從文本文件中提取單詞
- 4. 僅從文本文件中提取帶撇號的單詞
- 5. 單詞提取多行文本文件
- 6. 從文件中獲取單詞輸入
- 7. 從doc/docx文件中提取單詞c#
- 8. 從HTML文檔中提取文本到單詞列表中
- 9. 從R中的文本中提取英文單詞
- 10. 用golang從PDF中提取單詞?
- 11. 如何從行中提取單詞
- 12. 如何從URL中提取單詞?
- 13. 從序言列表中提取單詞
- 14. 從域名中提取單詞
- 15. 從序言結構中提取單詞
- 16. Ruby:從字符串中提取單詞
- 17. 從音頻剪輯中提取單詞
- 18. 從Wordnet中提取單詞列表
- 19. 如何讓Python從文本文件中讀取和提取單詞?
- 20. 如何根據上下文從文本中提取單詞
- 21. 提取文本文件中的第一個單詞,然後提取相應的單詞?
- 22. 從java中的文本文件中提取包含2個單詞的句子
- 23. 從文本中提取名詞(Java)
- 24. 從mysql中的文本字段中提取特定單詞
- 25. 從SQL中的文本字段中提取單詞
- 26. 從文本文件中讀取單個單詞並翻譯 - C
- 27. 從URL中提取詞
- 28. 如何在matlab中用條件提取文本中的單詞?
- 29. 從詞典軟件中提取聲音(「.t」文件)
- 30. 如何使用python從文本中提取單詞?
@Chistopher一個小小的詭辯 - 你可能想要添加'-s'來擠壓白色空間。 – potong