答案1
尝试按如下方式配置 grep:grep -Po '(?<= - )[^ ]*'
我想这取决于你使用的系统类型...-Po 无法在 mac osx 上工作,但在 centos 上工作正常:
[rust@JBLGSMR001 ~]$ cat data.txt
2017-06-07-17:44:45.5903 tcp(6) - 192.168.80.12 58647 192.168.80.140 9999: 44 S [linux 2.2]
2017-06-07-17:44:45.5904 tcp(6) - 192.168.80.12 58647 192.168.80.140 9999: 44 S [linux 2.2]
2017-06-07-17:44:45.5905 tcp(6) - 192.168.80.12 58647 192.168.80.140 9999: 44 S [linux 2.2]
2017-06-07-17:44:45.5906 tcp(6) - 192.168.80.12 58647 192.168.80.140 9999: 44 S [linux 2.2]
2017-06-07-17:44:45.5907 tcp(6) - 192.168.80.12 58647 192.168.80.140 9999: 44 S [linux 2.2]
2017-06-07-17:44:45.5908 tcp(6) - 192.168.80.12 58647 192.168.80.140 9999: 44 S [linux 2.2]
2017-06-07-17:44:45.5909 tcp(6) - 192.168.80.12 58647 192.168.80.140 9999: 44 S [linux 2.2]
[rust@JBLGSMR001 ~]$ cat data.txt | grep -Po '(?<= - )[^ ]*' >> output.txt
[rust@JBLGSMR001 ~]$ cat output.txt
192.168.80.12
192.168.80.12
192.168.80.12
192.168.80.12
192.168.80.12
192.168.80.12