cmd.exe 是否有类似 sed 的实用程序? [英] Is there any sed like utility for cmd.exe?

查看:43
本文介绍了cmd.exe 是否有类似 sed 的实用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Windows 命令行(cmd.exe)以编程方式编辑文件内容.在 *nix 中有用于此任务的 sed.Windows 中是否有任何有用的本机等价物?

I want to programmatically edit file content using windows command line (cmd.exe). In *nix there is sed for this tasks. Is there any useful native equivalent in windows?

推荐答案

今天 powershell 救了我.

Today powershell saved me.

对于 grep 有:

get-content somefile.txt | where { $_ -match "expression"}

select-string somefile.txt -pattern "expression"

对于 sed 有:

get-content somefile.txt | %{$_ -replace "expression","replace"}

有关替换 PowerShell 功能的更多详细信息,请参阅this微软文章.

For more detail about replace PowerShell function see this Microsoft article.

这篇关于cmd.exe 是否有类似 sed 的实用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆