string - 从 NSIS 脚本中查找文件中的字符串模式

标签 string find nsis

在 NSIS 安装程序脚本中,我尝试检查给定的 httpd.conf 文件是否包含以下行:

Include "c:\xxx\yyy.conf"

如果是这样,那么我的安装程序脚本不会将其附加到文件中,否则,它将附加它。

我已经完成了 {LineFind},但不确定这是否真的能实现我想要实现的目标。

从 NSIS 脚本对文本文件执行“grep”的最简单方法是什么?

谢谢!

最佳答案

这里是一个在文件中搜索给定行的示例,使用 LogicLib 来简化语法。一旦找到该行,搜索就会停止。该示例适用于示例脚本本身:

# find.nsi : sample for LineFind from TextFunc.nsh
!include "textfunc.nsh"
!include "logiclib.nsh"
OutFile "find.exe"

!define lookfor `Section`   ;will find
;!define lookfor `Sectionn` ;will not find
Var found

Section
    StrCpy $found 0
    ${LineFind} "find.nsi" "/NUL" "1:-1" "GrepFunc"

    ${if} $found = 1 
        MessageBox MB_OK "string found"
    ${else}
        MessageBox MB_OK "string NOT found"
    ${endIf}

SectionEnd

Function GrepFunc
    ${TrimNewLines} '$R9' $R9
    DetailPrint "test for line $R8 `$R9`"
    ${if} $R9 == "${lookfor}" 
        StrCpy $found 1         ;set flag
        Push "StopLineFind"     ;stop find
    ${else}
        Push 0                  ;ignore -> continue
    ${endIf}
FunctionEnd

关于string - 从 NSIS 脚本中查找文件中的字符串模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14962645/

相关文章:

cmd - 在 NSIS 中静默运行批处理文件

按字符串搜索 PHP MySQL 表 - 使用散列?

python - 如何在python中使用 ":"而不是 "="编写.cfg文件

arrays - 如何计算find命令返回的文件数量?

c++ - 成对 vector : first pair values are non-sorted and second pair values are sorted: how to find a sorted value when having the non-sorted one

dialog - NSIS 为卸载程序使用选定的语言

electron - 将自定义页面/字段添加到使用 electron-builder 创建的 NSIS 设置

javascript - 如何修复 "let i = 0 "循环中的 "for"值在完成循环后再次变为 0?

c# - 控制台输出到文本框

regex - 如何使用带有正则表达式的find,-exec,grep和sed替换部分文本行?