iT邦幫忙

0

powershell 腳本

kbin 2020-08-24 16:29:451052 瀏覽
  • 分享至 

  • xImage

各位神人大大好
我是剛踏入這個領域的新人
但有點問題的是
我需要做一個可以輸入特定值,然後去從某個檔案裡抓相關的資料
例如
輸入1 去檔案裡抓a
輸入2 抓b
有沒有神仁老師可以幫幫忙

froce iT邦大師 1 級 ‧ 2020-08-24 16:55:01 檢舉
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_switch?view=powershell-7

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-7

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string?view=powershell-7
froce iT邦大師 1 級 ‧ 2020-08-24 16:55:23 檢舉
上面三篇看完組合就行了
kbin iT邦新手 5 級 ‧ 2020-08-25 10:48:58 檢舉
感謝大大解圍
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
froce
iT邦大師 1 級 ‧ 2020-08-24 23:46:23
$hashPat = @{ 1 = "a"; 2 = "b"; 3 = "c"}
$input = [int](Read-Host)
try {
    Get-Content 'C:\Users\froce\Desktop\新文字文件 (2).txt'|Select-String -Pattern $hashPat[$input]
} catch {
    "有錯誤"
}
pause

文件路徑自己改

kbin iT邦新手 5 級 ‧ 2020-08-25 10:49:14 檢舉

感謝!!
剛剛測試可以了!!

我要發表回答

立即登入回答