Substitua os valores de algumas chaves em um arquivo de texto de linha única

1

Eu tenho um arquivo grande chamado res.dat que contém certos dados que eu preciso modificar. Todos os dados estão em uma única linha.

Por exemplo:

L1TRAIN="200" NEEDL2="14" L2TRAIN="300" NEEDL3="16" L3TRAIN="400" NEEDL4="99" L4TRAIN="600" NEEDL5="99" L5TRAIN="900" DELAY="60" COOLTIME="0" KORNAME="화염풍" SKILLTYPE="0" TOOLTIP="A defensive spell that allows you to push away enemies of lower level. This spell has a fixed chance for success. The range of the spell and chance of success increase with training." /><VALUE MAGID="9" MAGNAME="Lavastrike" TYPE="0" EFFECTTYPE="5" EFFECT="7" SPELL="11" POWER="14" MAXPOWER="18" DEFSPELL="15" DEFPOWER="12" DEFMAXPOWER="16" JOB="1" PHASE="0" NEEDL1="20" L1TRAIN="500" NEEDL2="22" L2TRAIN="600" NEEDL3="24" L3TRAIN="700" NEEDL4="99" L4TRAIN="900" NEEDL5="99" L5TRAIN="1200" DELAY="80" COOLTIME="0" KORNAME="염사장" SKILLTYPE="0" TOOLTIP="A spell that shoots out line of fire along the ground, damaging all enemies caught within the fire. Its damage increases with training." /><VALUE MAGID="10" MAGNAME="LightningBeam" TYPE="2" EFFECTTYPE="6" EFFECT="8" SPELL="12" POWER="14" MAXPOWER="14" DEFSPELL="15" DEFPOWER="12" DEFMAXPOWER="16" JOB="1" PHASE="0" NEEDL1="21" L1TRAIN="500" NEEDL2="23" L2TRAIN="600" NEEDL3="25" L3TRAIN="700" NEEDL4="99" L4TRAIN="900" NEEDL5="99" L5TRAIN="1200" DELAY="80" COOLTIME="0" KORNAME="뢰인장" SKILLTYPE="0"

Eu preciso executar um script que procure os dados nas aspas duplas de L1TRAIN , L2TRAIN , L3TRAIN , L4TRAIN e L5TRAIN e atualize todos eles para L1TRAIN="100" L2TRAIN="200" L3TRAIN="300" L4TRAIN="400" L5TRAIN="500" Há cargas que precisam ser modificados, todos os dados estão em uma linha.

A saída do exemplo deve ser:

L1TRAIN="100" NEEDL2="14" L2TRAIN="200" NEEDL3="16" L3TRAIN="300" NEEDL4="99" L4TRAIN="400" NEEDL5="99" L5TRAIN="500" DELAY="60" COOLTIME="0" KORNAME="화염풍" SKILLTYPE="0" TOOLTIP="A defensive spell that allows you to push away enemies of lower level. This spell has a fixed chance for success. The range of the spell and chance of success increase with training." /><VALUE MAGID="9" MAGNAME="Lavastrike" TYPE="0" EFFECTTYPE="5" EFFECT="7" SPELL="11" POWER="14" MAXPOWER="18" DEFSPELL="15" DEFPOWER="12" DEFMAXPOWER="16" JOB="1" PHASE="0" NEEDL1="20" L1TRAIN="100" NEEDL2="22" L2TRAIN="200" NEEDL3="24" L3TRAIN="300" NEEDL4="99" L4TRAIN="400" NEEDL5="99" L5TRAIN="500" DELAY="80" COOLTIME="0" KORNAME="염사장" SKILLTYPE="0" TOOLTIP="A spell that shoots out line of fire along the ground, damaging all enemies caught within the fire. Its damage increases with training." /><VALUE MAGID="10" MAGNAME="LightningBeam" TYPE="2" EFFECTTYPE="6" EFFECT="8" SPELL="12" POWER="14" MAXPOWER="14" DEFSPELL="15" DEFPOWER="12" DEFMAXPOWER="16" JOB="1" PHASE="0" NEEDL1="21" L1TRAIN="100" NEEDL2="23" L2TRAIN="200" NEEDL3="25" L3TRAIN="300" NEEDL4="99" L4TRAIN="400" NEEDL5="99" L5TRAIN="500" DELAY="80" COOLTIME="0" KORNAME="뢰인장" SKILLTYPE="0"
    
por Rarara221 23.07.2016 / 00:27

1 resposta

0

Aqui está uma maneira de fazer isso com sed :

sed 's/\(L\([1-5]\)TRAIN="\)[^"]*/0/g' res.dat

isso usa agrupamento e retro-referência, substituindo qualquer ocorrência de

LnTRAIN="anything_except_double_quote

com

LnTRAIN="n00

em que n é um número entre 1 e 5 .

    
por 23.07.2016 / 20:54