【问题标题】:How to add comma at the end of line in 3 GB text file?如何在 3 GB 文本文件的行尾添加逗号?
【发布时间】:2019-07-19 14:12:36
【问题描述】:

我有一个以 .json 扩展名命名的 3GB 数据集。我想在除最后一行之外的每一行末尾添加逗号以验证 JSON 文件并导入 excel。 Notepad++ 不支持大文件。

我尝试以编程方式添加逗号,它在小文件上效果很好,但在大文件上效果不佳。我还尝试了 010 Editor、UltraEdit、Sublime Text,但没有任何帮助。 需要更换这个:

{
  "tweet_id": "3600118565656676",  
  "tweet_city": "mansfield-engj9-gb", 
  "tweet_latitude": "53.130483", 
  "tweet_longitude": "-1.141419"
}

带:

{  
  "tweet_id": "3600118565656676", 
  "tweet_city": "mansfield-engj9-gb", 
  "tweet_latitude": "53.130483", 
  "tweet_longitude": "-1.141419"
},

【问题讨论】:

  • 你的意思是它不起作用是程序崩溃了吗?
  • 它适用于 1.38MB 的文本文件,但是当我尝试使用 3GB 的文本文件时它没有响应,我已经等了将近 6 个小时但什么也没发生
  • 我的问题通过在 Sublime 文本编辑器上使用查找和替换解决了。

标签: json text dataset notepad++


【解决方案1】:

使用记事本++:

  • Ctrl+H
  • 查找内容:(?<=})(?!\s*,)
  • 替换为:,
  • 检查环绕
  • 检查正则表达式
  • 全部替换

说明:

(?<=        # positive lookbehind, make sure we have before:
  }         # closing curly brace
)           # end lookbehind
(?!         # negative lookahead, make sure we haven't after:
  \s*,      # 0 or more space and a comma
)           # end lookbehind

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-19
    • 2021-12-30
    • 2016-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多