如何读取文本文件中定义的参数值
How to read value of parameter defined in text file
我正在使用以下命令读取 txt 文件中定义的参数值。
$asid = Get-Content -Path config.cfg | Select-String -Pattern 'NW_GetSid' | ForEach-Object { $_.line.split('= ') }
参数在文件中定义如下:
Hostname = hostname
NW_GetSid = ABC
该命令先给出空行输出,然后输出:
Blank line
ABC
如何避免结果中出现空行,因为我只需要 ABC
来存储在 asid 变量中?
我会使用正则表达式来检索您想要的值 属性
$asid = [regex]::Match((get-content config.cfg -Raw), 'NW_GetSid\s*=\s*(\w+)').Groups[1].Value
我正在使用以下命令读取 txt 文件中定义的参数值。
$asid = Get-Content -Path config.cfg | Select-String -Pattern 'NW_GetSid' | ForEach-Object { $_.line.split('= ') }
参数在文件中定义如下:
Hostname = hostname
NW_GetSid = ABC
该命令先给出空行输出,然后输出:
Blank line
ABC
如何避免结果中出现空行,因为我只需要 ABC
来存储在 asid 变量中?
我会使用正则表达式来检索您想要的值 属性
$asid = [regex]::Match((get-content config.cfg -Raw), 'NW_GetSid\s*=\s*(\w+)').Groups[1].Value