我有一个属性文件,其中一个属性看起来像这个
tls.default.cipherSuites = TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,\
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,\
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,\
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,\
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,\
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,\
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,\
TLS_DHE_RSA_WITH_AES_128_CBC_SHA,\
TLS_RSA_WITH_AES_128_GCM_SHA256,\
TLS_RSA_WITH_AES_128_CBC_SHA256,\
TLS_RSA_WITH_AES_128_CBC_SHA,\
TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256,\
TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256,\
TLS_ECDH_RSA_WITH_AES_128_CBC_SHA,\
TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256,\
TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256,\
TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA,\
TLS_EMPTY_RENEGOTIATION_INFO_SCSV
我想只显示属性名称而不显示其值。我试过下面的命令
Get-Content -Path "C:\Test\run_pa.properties" |
Where-Object { ! $_.StartsWith("#") } |
? { $_.trim() -ne "" } | ForEach-Object { $_ -replace '=.*' }
但我的输出如下
tls.default.protocols
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,\
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,\
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,\
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,\
TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,\
TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,\
TLS_DHE_RSA_WITH_AES_128_CBC_SHA,\
TLS_RSA_WITH_AES_128_GCM_SHA256,\
TLS_RSA_WITH_AES_128_CBC_SHA256,\
TLS_RSA_WITH_AES_128_CBC_SHA,\
TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256,\
TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256,\
TLS_ECDH_RSA_WITH_AES_128_CBC_SHA,\
TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256,\
TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256,\
TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA,\
TLS_EMPTY_RENEGOTIATION_INFO_SCSV
如何避免此方案的属性值并仅获取属性名称?
答案 0 :(得分:0)
以下内容将这些行过滤到那些不以#
开头且包含=
的行,然后从=
之前删除以可选空格开头的所有内容,只是属性名称:
(Get-Content "C:\Test\run_pa.properties") -notmatch '^#' -match '=' -replace '\s*=.*'
答案 1 :(得分:-1)
使用Get-Content
上的string
选项始终只获得一个=
(v4和v5之间存在版本差异),而不是每行的数组。然后只需将.Trim(' ')
符号拆分,然后使用$content = Get-Content -Path $path -Raw
$propertyName = $content .Split('=')[0].Trim(' ')
修剪空白:
gss %>%
select(class) %>%
str()