Search code examples
linuxawksedhiddencut

delete first line and 3 columns from txt file


I have a file in the following format:

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

I want to delete first line and the mac col from all the lines , The output should be:

192.168.1.1
192.168.1.2
192.168.1.3
192.168.1.23

and the command run in background please I don't need to show result in terminal window


Solution

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

    In action

    $ 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
    

    For silent output, you could direct the output to another file.

    $ 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