gpt4 book ai didi

postgresql - 我想将这些列解析为 psql 表,但如何处理空字段?

转载 作者:行者123 更新时间:2023-11-29 13:59:13 28 4
gpt4 key购买 nike

我想将这些列解析为 psql 表,但如何处理空字段?使用此命令:“awk '{print $3;}' text.txt ”它忽略空格并写入下一列编号..

       StartTime           LastTime            SrcAddr            DstAddr  Sport  Dport  SrcPkts  DstPkts     SrcBytes     DstBytes 
13:14:52.088291 13:14:52.088291 192.168.0.23 192.168.0.255 57621 57621 1 0 86 0
13:14:54.936682 13:14:54.936682 192.168.0.23 192.168.0.255 17500 17500 1 0 243 0
13:14:54.936479 13:14:54.936479 192.168.0.23 17500 17500 1 0 243 0
13:14:56.056179 13:14:56.056179 192.168.0.163 17500 17500 1 0 208 0
13:14:56.056370 13:14:56.056370 192.168.0.163 192.168.0.255 17500 17500 1 0 208 0
13:15:00.027462 13:15:00.027462 192.168.0.170 192.168.0.255 17500 17500 1 0 146 0
13:15:00.652690 13:15:00.652874 192.168.0.166 443 57201 1 1 121 66
13:15:04.636177 13:15:04.636177 192.168.0.163 192.168.0.255 57621 57621 1 0 86 0
13:15:09.622847 13:15:09.622847 192.168.0.166 38029 53 1 0 76 0
13:15:13.138197 13:15:13.138197 192.168.0.158 192.168.0.255 57621 57621 1 0 86 0
13:15:15.429763 13:15:15.429763 192.168.0.151 192.168.0.255 57621 57621 1 0 86 0
13:15:19.793651 13:15:19.793651 192.168.0.163 192.168.0.255 138 138 1 0 280 0
13:15:19.795815 13:15:19.795815 192.168.0.90 192.168.0.255 137 137 1 0 92 0
13:15:20.342669 13:15:20.342669 192.168.0.23 192.168.0.255 137 137 1 0 92 0
13:14:40.721537 13:14:42.016881 192.168.0.136 192.168.0.166 22 59301 11 14 1334 1404
13:15:24.981466 13:15:24.981466 192.168.0.23 255.255.255.255 17500 17500 1 0 243 0
13:15:24.981666 13:15:24.981666 192.168.0.23 192.168.0.255 17500 17500 1 0 243 0
13:14:40.996353 13:14:41.996328 192.168.0.22 2 0 120 0
13:14:41.203309 13:15:41.171881 66 66 31 0 1984 0
13:15:26.116537 13:15:26.116537 192.168.0.163 17500 17500 1 0 208 0
13:15:26.116728 13:15:26.116728 192.168.0.163 192.168.0.255 17500 17500 1 0 208 0
13:14:41.863153 13:15:41.852795 0 0 31 0 1860 0
13:15:01.195960 13:15:03.192229 192.168.0.234 3 0 180 0
13:15:04.636774 13:15:04.636774 192.168.0.91 192.168.0.163 1 0 60 0
13:15:10.398423 13:15:10.398423 192.168.0.110 192.168.0.1 1 0 60 0
13:15:40.800831 13:15:40.913802 192.168.0.152 192.168.0.1 49556 53 2 2 148 689

最佳答案

您可以通过位置指定获取数据的位置,修剪它并使用 awk 打印它

awk '{a=substr($0,40,17);gsub(/ */,"",a);print a}' file
SrcAddr
192.168.0.23
192.168.0.23
192.168.0.23

192.168.0.163
192.168.0.170

192.168.0.163
192.168.0.166
192.168.0.158
192.168.0.151
192.168.0.163
192.168.0.90
192.168.0.23
192.168.0.136
192.168.0.23
192.168.0.23


192.168.0.163
192.168.0.163


192.168.0.91
192.168.0.110
192.168.0.152

关于postgresql - 我想将这些列解析为 psql 表,但如何处理空字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24508775/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com