我正在尝试使用 AWK 将文本文档中的每个单词放在新行上。我真的不知道如何使用 AWK,但我在网上找到了一些命令应该可以解决我的问题。我尝试过以下命令:
$ awk '{ for (i = 1; i <= NF; i++) print $i }' input.txt > output.txt
Run Code Online (Sandbox Code Playgroud)
和
$ awk '{c=split($0, s); for(n=1; n<=c; ++n) print s[n] }' input.txt > output.txt
Run Code Online (Sandbox Code Playgroud)
但是,这两个命令具有相同的效果,即删除所有空格。
为了清楚起见,假设 input.txt 包含文本:
The fox jumped over the dog
Run Code Online (Sandbox Code Playgroud)
输出.txt 应包含:
The
fox
jumped
over
the
dog
Run Code Online (Sandbox Code Playgroud)
然而,output.txt 包含:
Thefoxjumpedoverthedog
Run Code Online (Sandbox Code Playgroud)
我在 Windows 7 上使用 Cygwin 来使用这些命令。命令中是否缺少某些内容?