微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

AutoHotKey - 替换文件中的多行

如何解决AutoHotKey - 替换文件中的多行

我对 AutoHotkey 还很陌生,我用它来将 API JSON 文件从 URL 拉入文件。我已经想出了如何替换单行文本来替换无效的 JSON 对象,但现在我正在尝试在文件中找到一个模式,并在将文件解析为 sql 表之前添加另外两行。

目前正在寻找以下多行模式:

<CytoscapeComponent 
    layout={{ name: "circle" }}
    elements={elements} 
    style={ { width: '600px',height: '600px' } } 

    stylesheet={[
      {
        selector: 'edge',style: {
          width: 5,targetArrowShape: 'triangle',curveStyle: 'bezier'
        }
      }
    ]}
  />

需要在第一行后添加以下两行:

"AAA": x.xx,*Note: x.xx is a decimal number that can change per record.*
}

最终结果需要:

"BBB" {
  "CCC": NULL

解决方法

编辑 JSON 文件时,有很多更好的方法可以做到这一点。但是,如果您只想插入一些行,您可以这样做:

oldFile := "original_file.json"
newFile := "edited_file.json"

insertText =
(
"BBB" {
  "CCC": NULL
)

Loop,Read,% oldFile,% newFile
{
    FileAppend,%A_LoopReadLine%`n
    
    ; If last written line is a match,add new lines
    if RegExMatch(A_LoopReadLine,"""AAA"": \d+.\d+,")
    {    
        FileAppend,%insertText%`n
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。