Windows 上等效的“grep”和“sed”命令

5 windows powershell

我正在使用我拥有的域进行一些测试,我希望在执行 TXT 查询时,接收 Base64 中的字符串并对其进行解码以显示消息。

在 Linux 上,它可以完美运行:

$ dig -t txt my.domain.com +short | sed -e 's/^"//' -e 's/"$//' | base64 -d > file.txt
$ cat file.txt
Run Code Online (Sandbox Code Playgroud)

测试我的txt记录

现在我想做同样的事情,只不过在Windows中,默认情况下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}
Run Code Online (Sandbox Code Playgroud)

我怎样才能使上面的命令(Linux)在Windows上工作,只进行base64的搅拌和解码来显示消息。

pos*_*ote 5

或者花必要的时间学习 PowerShell,利用 Youtube 上的所有免费资源和视频来了解 PowerShell 的所有部分,以及本机可以完成哪些操作以及何时需要自己编码以及何时需要引入 3rdP 工具。

\n\n

这不是第一次被问及这个问题。使用“PowerShell Sed”和“PowerShell Grep”进行快速网络搜索,将向您展示这些内容甚至示例的良好列表。

\n\n
\n

Get-Content 获取指定位置处的项目内容。

\n\n

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

\n\n

Select-String 在字符串和文件中查找文本。

\n\n

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-string?view=powershell-7

\n\n

PowerShell 中的 sed

\n\n

https://docs.microsoft.com/en-us/archive/blogs/sergey_babkins_blog/sed-in-powershell

\n\n

PowerShell \xe2\x80\x93 UNIX SED 等效 \xe2\x80\x93 更改文件中的文本

\n\n

https://www.kittell.net/code/powershell-unix-sed-equivalent-change-text-file

\n\n

在 PowerShell 中使用 sed 和 grep

\n\n

https://www.catapultsystems.com/blogs/using-sed-and-grep-in-powershell

\n\n

http://www.systemcentercentral.com/using-sed-and-grep-in-powershell

\n\n

Grep,PowerShell 方式

\n\n

https://communary.net/2014/11/10/grep-the-powershell-way

\n\n

如何在 PowerShell 中 \xe2\x80\x9cgrep\xe2\x80\x9d

\n\n

https://antjanus.com/blog/web-development-tutorials/how-to-grep-in-powershell

\n\n

如何在 PowerShell 中进行 Grep

\n\n

https://www.adamfowlerit.com/2017/02/how-to-grep-in-powershell

\n\n

快速提示:PowerShell Grep 等效项

\n\n

https://dereknewton.com/2010/12/powershell-grep-equivalent

\n\n

POWERSHELL:搜索 POWERSHELL 的字符串或 Grep

\n\n

https://www.thomasmaurer.ch/2011/03/powershell-search-for-string-or-grep-for-powershell

\n
\n\n

其次,利用Microsoft powershellgallery其次,直接在 PowerShell 控制台或新的 Windows 终端中

\n\n
Find-Module -Name \'*grep*\' | Format-Table -AutoSize\n\nVersion Name     Repository Description                 \n------- ----     ---------- -----------                 \n1.1.0   PoshGrep PSGallery  Greplike PowerShell function\n\n\n\n Find-Package -Name \'*grep*\' | Format-Table -AutoSize\n\nName      Version        Source    Summary                                                                \n----      -------        ------    -------                                                                \nwk.Grep   0.2.0          nuget.org Package Description                                                    \nLiv.Grep  1.0.5436.17982 nuget.org Grep utility written in c#. Makes it easy to query command line outputs\nAstroGrep 4.3.2          nuget.org This application and its source code are freely distributable.         \nGRepo     1.0.0          nuget.org GRepo                                                                  \nPoshGrep  1.1.0          PSGallery Greplike PowerShell function\n
Run Code Online (Sandbox Code Playgroud)\n\n

...或者使用 PowerShell 编辑器时 - 提供弹出帮助/IntelliSense(内置 PowerShell_ISEVScode 下载PowerShell Plus,它们是免费的)或(Sapien\'s PowerShell Studio ) - 需要花钱。)

\n\n

最后,您也在代码中使用 dig 。为此,请参阅:

\n\n
\n

PowerShell:查询 DNS 服务器的 A、PTR、MX、NS 等记录

\n\n

如何使用 PowerShell 获取 DNS 记录

\n
\n