小编Asi*_*r12的帖子

使用 sed 仅在第一次出现的模式匹配后查找并替换文件中的文本

假设我有以下输入文件:

Server 'Test AB'
    option type 'ss'
    option port '1234'
    option timeout '60'

Server 'Test CD'
    option type 'ss'
    option port '1234'
    option timeout '60'

Server 'Test EF'
    option type 'ss'
    option port '1234'
    option timeout '60'

Server 'Test GH'
    option type 'ss'
    option port '1234'
    option timeout '60'
Run Code Online (Sandbox Code Playgroud)

现在我想使用 sed 将“选项端口'1234'”与“选项端口'9876'”交换,但我只想为服务器“Test EF”执行此操作。所有其他端口应保持不变。

输出应如下所示:

Server 'Test AB'
    option type 'ss'
    option port '1234'
    option timeout '60'

Server 'Test CD'
    option type 'ss'
    option port '1234'
    option timeout '60'

Server 'Test …
Run Code Online (Sandbox Code Playgroud)

linux text-editing bash sed

4
推荐指数
1
解决办法
8363
查看次数

标签 统计

bash ×1

linux ×1

sed ×1

text-editing ×1