c#文本文件文本替换
Linux provides a lot of tools to ease system administrators work. One of them is to replace command which simple search text files to replace string and create a new text file. Replace command comes with MySQL Server packages. IF MySQL is not installed we can not use replace command.
Linux提供了许多工具来简化系统管理员的工作。 其中之一是replace命令,该命令简单地搜索文本文件即可替换字符串并创建一个新的文本文件。 MySQL服务器软件包随附了Replace命令。 如果未安装MySQL,则无法使用replace命令。
替换命令 (Replace Command)
We can use replace command to change a string in text files.
我们可以使用replace命令更改文本文件中的字符串。
$ replace BEFORE AFTER < YOURCOMMAND > NEWTEXTFILE
BEFORE is the string we search for
BEFORE是我们要搜索的字符串
AFTER is the new string
AFTER是新字符串
< YOURCOMMAND is our original text file
<YOURCOMMAND是我们的原始文本文件
> NEWTEXTFILEis newly created text file with replace string
> NEWTEXTFILE是新创建的带有替换字符串的文本文件
文件的开始和结束(Beginning and End Of File)
We can specify the beginning and end of the file with ^ $
我们可以用^ $指定文件的开头和结尾
$ replace ^Before After < yourcommand > newtextfile
Replace string Before which is at the beginning of the line
替换字符串Before ,该字符串在行的开头
Sed命令(Sed Command)
An alternative to replace command is sed. Sed is generally installed by default most of the distributions. So we can replace sed with replace.
sed是替代命令的替代方法。 通常,大多数发行版默认都安装了Sed。 因此,我们可以将sed替换为replace。
$ sed 's/Before/After/g' < yourcommand.txt > newtextfile
OR
要么
$ sed 's/Before//After/g' yourcommand.txt
In this example replace done in place so the new file wouldn’t be created.
在此示例中,替换为完成,因此将不会创建新文件。
Perl老朋友 (Perl Old Friend)
We can accomplish replacement with Perl just like below. In the following example, we will change the text Before
with the After
text.
我们可以像下面这样用Perl完成替换。 在以下示例中,我们将文本“ Before
更改为“ After
文本。
perl -p -i -e 's/Before/After/g' yourcommand.txt
c#文本文件文本替换