如何替换特定文本行中的特定单词 [英] How to replace a specific word in a specific line of text

查看:134
本文介绍了如何替换特定文本行中的特定单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我有这个yaml文件,我想替换一个字符串

  socialspy:true 

与字符串

  socialspy:false 

但是我不知道如何去做。这里是完整的yaml文件

pre $时间戳
登录1395784099618
lastteleport 1395785353975
登出:1395777644566
静音:0
ipAddress:127.0.0.1
lastlocation:
world:world
x:-276.7695097103249
y:67.31022115326866
z: -354.327229975015
yaw:127.892334
pitch:20.817677
money:'155200.0'
logoutlocation:
world:world
x:-252.00777100946556
y: 76.56983022033046
z:-348.45387330548886
yaw:319.99237
pitch:19.562881
socialspy:true
godmode:true
afk:false
powertools:
静音:false


解决方案

假设您正在使用一个体面的操作系统,你的YAML文件被称为 doc

  sed -i's / socialspy:true / socialspy:false /'doc 


Okay, so I have this yaml file, and I want to replace a string

socialspy: true 

with the string

socialspy: false 

But I don't know how to. Here is the full yaml document

timestamps:
  login: 1395784099618
  lastteleport: 1395785353975
  logout: 1395777644566
  mute: 0
ipAddress: 127.0.0.1
lastlocation:
  world: world
  x: -276.7695097103249
  y: 67.31022115326866
  z: -354.327229975015
  yaw: 127.892334
  pitch: 20.817677
money: '155200.0'
logoutlocation:
  world: world
  x: -252.00777100946556
  y: 76.56983022033046
  z: -348.45387330548886
  yaw: 319.99237
  pitch: 19.562881
socialspy: true
godmode: true
afk: false
powertools:
muted: false

解决方案

Assuming you're using a decent OS and that your YAML document is called doc:

sed -i 's/socialspy: true/socialspy: false/' doc

这篇关于如何替换特定文本行中的特定单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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