从txt文件中删除第一行和第3列

时间:2017-10-10 05:25:09

标签: linux awk sed hidden cut

我有一个以下格式的文件:

Received 4 packets, got 4 answers, remaining 252 packets
52:54:00:12:35:00 192.168.1.1
52:54:00:12:35:00 192.168.1.2
08:00:27:87:d3:08 192.168.1.3
08:00:27:3e:99:5c 192.168.1.23

我想从所有行中删除第一行和mac col,输出应为:

192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.23

并且命令在后台运行,请不要在终端窗口中显示结果

1 个答案:

答案 0 :(得分:1)

awk 'NR != 1 {print $2}' file1

行动中

$ cat file1
Received 4 packets, got 4 answers, remaining 252 packets
52:54:00:12:35:00 192.168.1.1
52:54:00:12:35:00 192.168.1.2
08:00:27:87:d3:08 192.168.1.3
08:00:27:3e:99:5c 192.168.1.23
$ awk 'NR != 1 {print $2}' file1
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.23

对于静默输出,您可以将输出定向到另一个文件。

$ awk 'NR != 1 {print $2}' file1 > file2
$ cat file2
192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.23