我有一个关于 AWK 命令的快速问题。我需要命令打印到同一行的行尾,但是当它到达下一行时,我需要它在另一行上打印。以下示例将提供更好的清晰度。
假设我有一个文件:
0 1 2 3 This is line one
0 1 2 3 This is line two
0 1 2 3 This is line three
0 1 2 3 This is line four
我已经尝试了以下并得到了以下结果
awk '{for(i=5;i<=NF;i++) print $i}' fileName >> resultsExample1
我在 resultsExample1 中得到以下信息
This
is
line
one
This
is
line
two
And so on....
示例 2:
awk 'BEGIN {" "} {for(i=5;i<=NF;i++) printf $1}' fileName >> resultsExample2
对于 resultsExample2 我得到:
This is line one This is line two this is line three This is line four
我也试过:
awk 'BEGIN {" "} {for(i=5;i<=NF;i++) printf $1}' fileName >> resultsExample3
但是结果和上一个一样
最后,我想要以下内容:
This is line one
This is line two
This is line three
This is line four
我很感激任何帮助!提前致谢 :)