因此,我尝试将列与字段分隔符一起输出。
但在我的情况下它失败了。
awk.txt(Input file)
Sr No Name Sub Marks
1) Amit Physics 80
2) Rahul Maths 90
3) Shyam Biology 87
4) Kedar English 85
5) Hari History 89
我尝试过的 awk 命令如下:-
awk -F ' ' '{print $2 $3;}' awk.txt > output.txt
获得的输出:
NoName
AmitPhysics
RahulMaths
ShyamBiology
KedarEnglish
HariHistory
预期输出:
Name Sub
Amit Physics
Rahul Maths
Shyam Biology
Kedar English
Hari History
最佳答案
awk '{print $3,$4;}' awk.txt > output.txt
不需要指示字段分隔符。字段编号从 1 开始,因此您需要第三个和第四个字段。对于打印 OFS(输出字段分隔符),请使用逗号。
或者:
awk 'BEGIN{FS=OFS=" ";}{print $3,$4;}' awk.txt > output.txt
关于awk - 如何使用 awk 使用空格作为字段分隔符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45589981/