c#文本文件文本替换_如何替换许多文件中存在的文本?

c#文本文件文本替换

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
LEARN MORE  Linux Bash Arrays and Elements
了解更多Linux Bash数组和元素

翻译自: https://www.poftut.com/replace-text-exists-many-files/

c#文本文件文本替换

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值