在Python中记录表并将其他文本数据附加到.csv文件
我正在尝试将获得的数据添加到.csv文件中。在Python中记录表并将其他文本数据附加到.csv文件,python,bash,csv,logging,Python,Bash,Csv,Logging,我正在尝试将获得的数据添加到.csv文件中。 在横向上,它会像 TimeStamp-NMEA(GGA)-F1000a-NUIMWireless-CONF-........ TimeStamp2-NEMA(GGA2)-other access points in the other location . . . Simply I want to log all the access points in a file by using a Python loop. ~ $ sudo iwlis
在横向上,它会像
TimeStamp-NMEA(GGA)-F1000a-NUIMWireless-CONF-........
TimeStamp2-NEMA(GGA2)-other access points in the other location
.
.
.
Simply I want to log all the access points in a file by using a Python loop.
~ $ sudo iwlist wlan0 scan | python iwlistparse.py
Name Address Quality Channel Encryption
F1000a FC:F5:28:B0:29:CB 50 % 4 WPA v.1
NUIMWireless 00:26:99:4D:0D:31 26 % 11 Open
CONF 00:26:99:4D:0D:30 25 % 11 WPA v.1
OPAC 00:26:99:4D:0D:33 25 % 11 WPA v.1
eduroam 00:26:99:4D:0D:35 24 % 11 WPA v.1
STAFF 00:26:99:4D:0D:34 22 % 11 WPA2
STAFF 00:26:99:4D:0F:34 20 % 1 WPA2
NUIMWireless 00:26:99:4D:0F:31 19 % 1 Open
eduroam 00:26:99:4D:0F:35 17 % 1 WPA v.1
CONF 00:26:99:4D:0F:30 17 % 1 WPA v.1
OPAC 00:26:99:4D:0F:33 17 % 1 WPA v.1
如有任何建议,将不胜感激。提前感谢。您的问题需要重写,但如果数据是水平的,如问题第一部分所示,我建议使用
cut
:
cut -d- -f3 your_input
这将从分隔符为-
的文件中获取第三个字段
如果数据是在脚本输出中“垂直”给出的,只需获取第一个字段:
awk 'NF { print $1 }' your_input
它只打印所有非空行的第一个字段。谢谢,你知道有没有解析的好教程吗,我对Python和bash都很陌生。有很多!只需谷歌一下!:)