我有一个文本文件,它会说出他们登录的计算机名称和当前日期。
04/10/2017, "PC1" 04/10/2017, "PC4" 05/10/2017, "PC3" 09/10/2017, "PC2"
我在尝试运行脚本时遇到问题,该脚本将查找包含" PC2" 的任何行并删除该行:
get-content "c:\file.csv" | %{if($_ -match "PC2"){$_ -replace $_, ""}} | set-content c:\file.csv
答案 0 :(得分:4)
(Get-Content 'C:\File.csv') -notmatch 'PC2' | Set-Content 'C:\File1.csv'
您也可以使用正则表达式
文件扩展名为csv
Import-Csv 'C:\File.csv' -Header Logged,Computer |
where {$_.Computer -ne 'PC2'} |
Export-Csv 'C:\File.csv' -NoClobber -NoTypeInformation
答案 1 :(得分:1)
SERVER=gitlab.example.com
PORT=443
CERTIFICATE=/etc/gitlab-runner/certs/${SERVER}.crt
# Create the certificates hierarchy expected by gitlab
sudo mkdir -p $(dirname "$CERTIFICATE")
# Get the certificate in PEM format and store it
openssl s_client -connect ${SERVER}:${PORT} -showcerts </dev/null 2>/dev/null | sed -e '/-----BEGIN/,/-----END/!d' | sudo tee "$CERTIFICATE" >/dev/null
# Register your runner
gitlab-runner register --tls-ca-file="$CERTIFICATE" [your other options]
你走了。这利用了一个易于理解的通配符比较运算符,只过滤掉具有匹配字符串的行。