![Windows 上の同等の 'grep' および 'sed' コマンド](https://rvso.com/image/1615290/Windows%20%E4%B8%8A%E3%81%AE%E5%90%8C%E7%AD%89%E3%81%AE%20'grep'%20%E3%81%8A%E3%82%88%E3%81%B3%20'sed'%20%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89.png)
所有しているドメインでいくつかテストを行っていますが、TXT クエリを実行するときに、base64 で文字列を受信し、それをデコードしてメッセージを表示したいと考えています。
Linux では完璧に動作します:
$ dig -t txt my.domain.com +short | sed -e 's/^"//' -e 's/"$//' | base64 -d > file.txt
$ cat file.txt
TXTレコードをテストする
ここで、同じことを実行したいと思います。ただし、Windows では、デフォルトでは dig はありませんが、次のコマンドがあります。
C:\Users\User\xyz>powershell Resolve-DnsName my.domain.com -Type
TXT > test
C:\Users\Avell\xyz>type test
Name Type TTL Section Strings
---- ---- --- ------- -------
my.domain.com TXT 10557 Answer
{dGVzdGluZyBvdXQgbXkgdHh0IHJlY29yZHMK}
上記のコマンド (Linux) を、base64 での読み込みとデコードのみを行ってメッセージを表示するように Windows で動作するようにするにはどうすればよいでしょうか。
答え1
または、PowerShell を学習するために必要な時間を費やし、YouTube のすべての無料リソースとビデオを活用して、PowerShell のすべての部分を理解し、ネイティブで何ができるか、いつ自分でコーディングする必要があるか、いつサードパーティ ツールを取り込む必要があるかを把握します。
この質問は初めてではありません。「PowerShell Sed」と「PowerShell Grep」を使用して簡単に Web 検索すると、これらの適切なリストと例が表示されます。
Get-Content 指定された場所にある項目のコンテンツを取得します。
Select-String 文字列およびファイル内のテキストを検索します。
PowerShell での sed
https://docs.microsoft.com/en-us/archive/blogs/sergey_babkins_blog/sed-in-powershell
PowerShell – UNIX SED と同等 – ファイル内のテキストを変更する
https://www.kittell.net/code/powershell-unix-sed-equivalent-change-text-file
PowerShell で sed と grep を使用する
https://www.catapultsystems.com/blogs/using-sed-and-grep-in-powershell
http://www.systemcentercentral.com/using-sed-and-grep-in-powershell
PowerShell の Grep 方式
https://communary.net/2014/11/10/grep-the-powershell-way
PowerShell で「grep」する方法
https://antjanus.com/blog/web-development-tutorials/how-to-grep-in-powershell
PowerShell で Grep を実行する方法
https://www.adamfowlerit.com/2017/02/how-to-grep-in-powershell
クイックヒント: PowerShell Grep 相当
https://dereknewton.com/2010/12/powershell-grep-equivalent
POWERSHELL: 文字列の検索または POWERSHELL の GREP
https://www.thomasmaurer.ch/2011/03/powershell-search-for-string-or-grep-for-powershell
第二に、Microsoft PowerShell ギャラリーPowerShell コンソールまたは新しい Windows ターミナルで直接実行できます...
Find-Module -Name '*grep*' | Format-Table -AutoSize
Version Name Repository Description
------- ---- ---------- -----------
1.1.0 PoshGrep PSGallery Greplike PowerShell function
Find-Package -Name '*grep*' | Format-Table -AutoSize
Name Version Source Summary
---- ------- ------ -------
wk.Grep 0.2.0 nuget.org Package Description
Liv.Grep 1.0.5436.17982 nuget.org Grep utility written in c#. Makes it easy to query command line outputs
AstroGrep 4.3.2 nuget.org This application and its source code are freely distributable.
GRepo 1.0.0 nuget.org GRepo
PoshGrep 1.1.0 PSGallery Greplike PowerShell function
...または、ポップアップヘルプ/IntelliSenseを提供するPowerShellエディターを使用する場合(PowerShell_ISE組み込み、VScodeのダウンロード、PowerShell プラス(無料)または(Sapien の PowerShell Studio- お金がかかります。
最後に、コード内でも dig を使用しています。これについては、次を参照してください。