代码/Approach Golf:在文本文件中查找列太多的行
给定一个应该包含 10 个制表符分隔列(即 9 个制表符)的文本文件,我想查找具有超过 10 列(超过 9 个制表符)的所有行。每行以 CR-LF 结尾。
除上述之外,不假设任何有关数据、字段宽度等的信息。
关于方法和/或工作代码的评论将非常感激。打印违规行的行号也有奖励。
提前致谢!
编辑,正如评论者所指出的(谢谢!),您可以假设数据不包含制表符或 CRLF。
Given a text file that is supposed to contain 10 tab-delimited columns (i.e. 9 tabs), I'd like to find all rows that have more than 10 columns (more than 9 tabs). Each row ends with CR-LF.
Assume nothing about the data, field widths, etc, other than the above.
Comments regarding approach, and/or working code would be extremely appreciated. Bonus for printing line numbers of offending lines as well.
Thanks in advance!
EDIT, as pointed out by the commenter (thanks!), you can assume the data doesn't contain tabs or CRLF's.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需使用正则表达式:
(.*\t){10,}
Just use a regular expression:
(.*\t){10,}
或者,使用行号:
Or, with line numbers: