From 0fd980ebefc1668240bb81249154c852eaf340a3 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Tue, 29 Dec 2020 11:03:53 +0000 Subject: [PATCH] Added search-files.ps1 --- README.md | 5 +++-- Scripts/search-files.ps1 | 29 +++++++++++++++++++++++++++++ Scripts/turn-volume-down.ps1 | 2 +- Scripts/turn-volume-up.ps1 | 2 +- 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100755 Scripts/search-files.ps1 diff --git a/README.md b/README.md index fd3150a0..84f71e9d 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol * [new-email.ps1](Scripts/new-email.ps1) - starts the default email client to write a new email * [news.ps1](Scripts/news.ps1) - prints the latest news * [reboot.ps1](Scripts/reboot.ps1) - reboots the local computer (needs administrator rights) +* [search-files.ps1](Scripts/search-files.ps1) - searches the given pattern in the given files * [scan-ports.ps1](Scripts/scan-ports.ps1) - scans the network for open/closed ports * [send-email.ps1](Scripts/send-email.ps1) - sends an email message * [send-tcp.ps1](Scripts/send-udp.ps1) - sends a TCP message to the given IP address and port @@ -67,8 +68,8 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol * [train-dns-cache.ps1](Scripts/train-dns-cache.ps1) - trains the DNS cache with frequently used domain names * [translate-file.ps1](Scripts/translate-file.ps1) - translates the given file from source to target language * [translate-text.ps1](Scripts/translate-text.ps1) - translates the given text into other languages -* [turn-volume-up.ps1](Scripts/turn-volume-up.ps1) - turns the volume up (+10% by default) -* [turn-volume-down.ps1](Scripts/turn-volume-down.ps1) - turns the volume down (-10% by default) +* [turn-volume-up.ps1](Scripts/turn-volume-up.ps1) - turns the audio volume up (+10% by default) +* [turn-volume-down.ps1](Scripts/turn-volume-down.ps1) - turns the audio volume down (-10% by default) * [txt2wav.ps1](Scripts/txt2wav.ps1) - converts text into a audio .WAV file * [unmute-audio.ps1](Scripts/unmute-audio.ps1) - unmutes audio * [weather.ps1](Scripts/weather.ps1) - prints the current weather forecast diff --git a/Scripts/search-files.ps1 b/Scripts/search-files.ps1 new file mode 100755 index 00000000..2ea4ff86 --- /dev/null +++ b/Scripts/search-files.ps1 @@ -0,0 +1,29 @@ +#!/snap/bin/powershell + +# Syntax: ./search-files.ps1 [] [] +# Description: searches the given pattern in the given files +# Author: Markus Fleschutz +# Source: github.com/fleschutz/PowerShell +# License: CC0 + +param([String]$Pattern, [String]$Path) + +Set-StrictMode -Version Latest + +try { + if ($Pattern -eq "" ) { + $Pattern = read-host "Enter search pattern" + } + if ($Path -eq "" ) { + $Path = read-host "Enter path to files" + } + + $List = Select-String -Path $Path -Pattern "$Pattern" + foreach ($Item in $List) { + write-output "$($Item.Path) @$($Item.LineNumber)`t$($Item.Line)" + } + exit 0 +} catch { + write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" + exit 1 +} diff --git a/Scripts/turn-volume-down.ps1 b/Scripts/turn-volume-down.ps1 index e66c3b22..cc75dcb8 100755 --- a/Scripts/turn-volume-down.ps1 +++ b/Scripts/turn-volume-down.ps1 @@ -1,7 +1,7 @@ #!/snap/bin/powershell # Syntax: ./turn-volume-down.ps1 [] -# Description: turns the volume down (-10% by default) +# Description: turns the audio volume down (-10% by default) # Author: Markus Fleschutz # Source: github.com/fleschutz/PowerShell # License: CC0 diff --git a/Scripts/turn-volume-up.ps1 b/Scripts/turn-volume-up.ps1 index e57467b4..50b58a87 100755 --- a/Scripts/turn-volume-up.ps1 +++ b/Scripts/turn-volume-up.ps1 @@ -1,7 +1,7 @@ #!/snap/bin/powershell # Syntax: ./turn-volume-up.ps1 [] -# Description: turns the volume up (+10% by default) +# Description: turns the audio volume up (+10% by default) # Author: Markus Fleschutz # Source: github.com/fleschutz/PowerShell # License: CC0