且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何替换特定文本行中的特定单词

更新时间:2023-01-15 18:10:49

假设您正在使用一个体面的操作系统,你的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