【发布时间】:2021-09-18 18:18:14
【问题描述】:
大家好,我在记事本++中有一个包含 71989 行的文件,大多数行有 11 个逗号 (,),因为我有 11 列但是当我在 SQL 中加载我的文件时我得到一些错误,因为有些行有 9 条记录,所以9个逗号。 notepad++ 中有没有办法找到哪些行有 9 个逗号而不是 11 个?
我也可以用python。
提前谢谢你
【问题讨论】:
大家好,我在记事本++中有一个包含 71989 行的文件,大多数行有 11 个逗号 (,),因为我有 11 列但是当我在 SQL 中加载我的文件时我得到一些错误,因为有些行有 9 条记录,所以9个逗号。 notepad++ 中有没有办法找到哪些行有 9 个逗号而不是 11 个?
我也可以用python。
提前谢谢你
【问题讨论】:
使用 Python,您可以计算每行出现的所有逗号...
'''
contents of data.txt (your SQL file for example)...
1,2,3,4,5,6,7,8,9,10,11,
,,,,,,,,,,,
,,,,,,,,,
,,,,,,,,,,,
1,2,3,4,5,6,7,8,9,
Note: Nine commas on the third and fifth lines.
'''
with open('data.txt') as f:
lines = f.readlines()
for line_number, line in enumerate(lines, 1):
if line.count(',') == 9:
print('Check line number: ' + str(line_number))
输出:
Check line number: 3
Check line number: 5
也许这有帮助:o?
【讨论】: