如何在 Powershell 中执行 head、tail、more、less、sed 的操作? [英] How to do what head, tail, more, less, sed do in Powershell?
本文介绍了如何在 Powershell 中执行 head、tail、more、less、sed 的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在windows上,使用Powershell,linux的head
、tail
、more
、less
等价命令有哪些> 和 sed
?
解决方案
Get-Content
(别名:gc
)是读取文本文件的常用选项.然后您可以进一步过滤:
gc log.txt |select -first 10 # 头gc -TotalCount 10 log.txt # 也是头gc 日志.txt |select -last 10 # 尾gc -Tail 10 log.txt # 也是 tail (自 PSv3),也比上面的选项快得多gc 日志.txt |如果您安装了它,则更多 # 或更少gc 日志.txt |%{ $_ -replace '\d+', '($0)' } # sed
这对于小文件来说已经足够了,大文件(超过几个 MiB)可能有点慢.
PowerShell 社区扩展 包括一些用于专门文件内容(例如 Get-FileTail)的 cmdlet.>
On windows, using Powershell, what are the equivalent commands to linux's head
, tail
, more
, less
and sed
?
解决方案
Get-Content
(alias: gc
) is your usual option for reading a text file. You can then filter further:
gc log.txt | select -first 10 # head
gc -TotalCount 10 log.txt # also head
gc log.txt | select -last 10 # tail
gc -Tail 10 log.txt # also tail (since PSv3), also much faster than above option
gc log.txt | more # or less if you have it installed
gc log.txt | %{ $_ -replace '\d+', '($0)' } # sed
This works well enough for small files, larger ones (more than a few MiB) are probably a bit slow.
The PowerShell Community Extensions include some cmdlets for specialised file stuff (e.g. Get-FileTail).
这篇关于如何在 Powershell 中执行 head、tail、more、less、sed 的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文