问题描述
什么是做一个查找和替换为给定的输入字符串最简单的方法,说 ABC
,并用另一个字符串替换,比如 XYZ
文件 /tmp/file.txt
?
What's the simplest way to do a find and replace for a given input string, say abc
, and replace with another string, say XYZ
in file /tmp/file.txt
?
我书面方式一个应用程序,并使用IronPython的通过SSH&MDASH执行命令;但我不知道Unix的那么好,不知道要寻找什么。
I am writting an app and using IronPython to execute commands through SSH — but I don't know Unix that well and don't know what to look for.
我听说猛砸,除了是一个命令行界面,可以是一个非常强大的脚本语言。所以,如果这是真的,我认为你可以像这样执行的操作。
I have heard that Bash, apart from being a command line interface, can be a very powerful scripting language. So, if this is true, I assume you can perform actions like these.
我可以使用bash做,什么是最简单的(一行)脚本来实现我的目标?
Can I do it with bash, and what's the simplest (one line) script to achieve my goal?
推荐答案
文件操作通常不会做被Bash,而是由猛砸调用程序,例如:
File manipulation isn't normally done by Bash, but by programs invoked by Bash, e.g.:
> perl -pi -e 's/abc/XYZ/g' /tmp/file.txt
的 -i
标志告诉它做就地更换。
The -i
flag tells it to do an in-place replacement.
请参阅男人perlrun
有关详细信息,包括如何采取原始文件的备份。
See man perlrun
for more details, including how to take a backup of the original file.
这篇关于查找并从里面bash命令文本文件替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!