Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python3.8中如何解析txt文件并将结果推送到postgres表_Python_Postgresql - Fatal编程技术网

在Python3.8中如何解析txt文件并将结果推送到postgres表

在Python3.8中如何解析txt文件并将结果推送到postgres表,python,postgresql,Python,Postgresql,我有以下文本文件,您可以使用下载: #/usr/bin/env bash 旋度-xhttps://linuxnet.ca/ieee/oui.txt -o linx_oui_macs.txt | grep'(十六进制)| sort | sed-e's/(十六进制)\t/-00-00-00/g' 我希望解析它并将结果推送到postgres表中。 下面是我想要生成的cols(第一条记录): id | mac|u hex | mac|u base|u 16 |组织|地址 1 | 00-22-72 |

我有以下文本文件,您可以使用下载:

#/usr/bin/env bash
旋度-xhttps://linuxnet.ca/ieee/oui.txt -o linx_oui_macs.txt | grep'(十六进制)| sort | sed-e's/(十六进制)\t/-00-00-00/g'
我希望解析它并将结果推送到
postgres
表中。 下面是我想要生成的
cols
(第一条记录):

id | mac|u hex | mac|u base|u 16 |组织|地址
1 | 00-22-72 | 002272 |美国Micro Feul Device Corp.| 2181 Buchanan Loop Ferndale WA 98248美国
id
列是
自动递增的
。 以下是我尝试过的:

以open('linx_oui_macs.txt','r')作为f的
:
text=f.read
text.split(“/t”)
但是它在标签页上分开,而且里面也有
/n
。任何人都可以帮助解析这个文件,提取相关字段并推送到postgres表吗

tvm