[英]Delete lines from file unless it starts with specific string
如果我只有-or
語句的一側,那么它可以工作,但是輸出文件只有一行,它表示true
。
如何顯示以任一指定行開頭的行?
(Get-Content "C:\Users\carst\Desktop\temp.xml") -match "<Module" -or (Get-Content "C:\Users\carst\Desktop\temp.xml") -match "<description>" | Out-File "C:\Users\carst\Desktop\temp2.xml"
由於它是XML文件,因此需要檢查節點之前是否有空格。
您可以加入這兩個搜索,還可以檢查以^\\s*
開頭是否有空格:
(Get-Content "C:\Users\carst\Desktop\temp.xml") -match '^\s*<(Module|description)' | Out-File "C:\Users\carst\Desktop\temp2.xml"
您可以使用豎線字符將它們全部加入一場比賽:
(Get-Content "C:\Users\carst\Desktop\temp.xml") -match '<Module|<description>' |
Out-File "C:\Users\carst\Desktop\temp2.xml
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.