修改双引号内的特定字段文本

修改双引号内的特定字段文本

我修改特定双引号内的所有内容。我的工作示例是:

<VALUE MAP_ID="1001" MAP="0" MAPNAME="BichonTown" SERVER="0" CHNSERVER="0" NEEDLEVEL="7" TIME="0" WEATHER="0" VEHICLE="1" PVP="0" MINE="0" CONTROL="" ENTERLV="0" ENTERQUEST="0" ENTERITEM="0" NORECONNECT="DQ_910" MINIMAP="1001" VER="200" APPLY_ROW="0" MAP_EXP_RATIO="0" MAP_DROP_RATIO="0" MAP_MONEY_RATIO="0" ORDERLIST="0" /><VALUE MAP_ID="1002" MAP="0_000" MAPNAME="TownHall" SERVER="1" CHNSERVER="1" NEEDLEVEL="0" TIME="1" WEATHER="0" VEHICLE="0" PVP="1" MINE="0" CONTROL="" ENTERLV="0" ENTERQUEST="0" ENTERITEM="0" NORECONNECT="5515" MINIMAP="0" VER="200" APPLY_ROW="0" MAP_EXP_RATIO="0" MAP_DROP_RATIO="0" MAP_MONEY_RATIO="0" ORDERLIST="0" /><VALUE MAP_ID="1003" MAP="0_001" MAPNAME="TownHall" SERVER="1" CHNSERVER="1" NEEDLEVEL="0" TIME="1" WEATHER="0" VEHICLE="0" PVP="1" MINE="0" CONTROL="" ENTERLV="0" ENTERQUEST="0" ENTERITEM="0" NORECONNECT="0" MINIMAP="0" VER="200" APPLY_ROW="0" MAP_EXP_RATIO="0" MAP_DROP_RATIO="0" MAP_MONEY_RATIO="0" ORDERLIST="0" /><VALUE MAP_ID="1004" MAP="0_002" MAPNAME="TownHall" SERVER="1" CHNSERVER="1" NEEDLEVEL="0" TIME="1" WEATHER="0" VEHICLE="0" PVP="1" MINE="0" CONTROL="" ENTERLV="0" ENTERQUEST="0" ENTERITEM="0" NORECONNECT="221" MINIMAP="0" VER="200" APPLY_ROW="0" MAP_EXP_RATIO="0" MAP_DROP_RATIO="0" MAP_MONEY_RATIO="0" ORDERLIST="0" /><VALUE MAP_ID="1005" MAP="1" MAPNAME="LostParadise" SERVER="1" CHNSERVER="1" NEEDLEVEL="7" TIME="0" WEATHER="0" VEHICLE="1" PVP="0" MINE="0" CONTROL="" ENTERLV="0" ENTERQUEST="0" ENTERITEM="0" NORECONNECT="11" MINIMAP="1002" VER="200" APPLY_ROW="0" MAP_EXP_RATIO="0" MAP_DROP_RATIO="0" MAP_MONEY_RATIO="0" ORDERLIST="0" />

里面的所有内容都NORECONNECT=""应该设置为0没有空格,只有字母、数字或下划线。结果应该看起来像

<VALUE MAP_ID="1001" MAP="0" MAPNAME="BichonTown" SERVER="0" CHNSERVER="0" NEEDLEVEL="7" TIME="0" WEATHER="0" VEHICLE="1" PVP="0" MINE="0" CONTROL="" ENTERLV="0" ENTERQUEST="0" ENTERITEM="0" NORECONNECT="0" MINIMAP="1001" VER="200" APPLY_ROW="0" MAP_EXP_RATIO="0" MAP_DROP_RATIO="0" MAP_MONEY_RATIO="0" ORDERLIST="0" /><VALUE MAP_ID="1002" MAP="0_000" MAPNAME="TownHall" SERVER="1" CHNSERVER="1" NEEDLEVEL="0" TIME="1" WEATHER="0" VEHICLE="0" PVP="1" MINE="0" CONTROL="" ENTERLV="0" ENTERQUEST="0" ENTERITEM="0" NORECONNECT="0" MINIMAP="0" VER="200" APPLY_ROW="0" MAP_EXP_RATIO="0" MAP_DROP_RATIO="0" MAP_MONEY_RATIO="0" ORDERLIST="0" /><VALUE MAP_ID="1003" MAP="0_001" MAPNAME="TownHall" SERVER="1" CHNSERVER="1" NEEDLEVEL="0" TIME="1" WEATHER="0" VEHICLE="0" PVP="1" MINE="0" CONTROL="" ENTERLV="0" ENTERQUEST="0" ENTERITEM="0" NORECONNECT="0" MINIMAP="0" VER="200" APPLY_ROW="0" MAP_EXP_RATIO="0" MAP_DROP_RATIO="0" MAP_MONEY_RATIO="0" ORDERLIST="0" /><VALUE MAP_ID="1004" MAP="0_002" MAPNAME="TownHall" SERVER="1" CHNSERVER="1" NEEDLEVEL="0" TIME="1" WEATHER="0" VEHICLE="0" PVP="1" MINE="0" CONTROL="" ENTERLV="0" ENTERQUEST="0" ENTERITEM="0" NORECONNECT="0" MINIMAP="0" VER="200" APPLY_ROW="0" MAP_EXP_RATIO="0" MAP_DROP_RATIO="0" MAP_MONEY_RATIO="0" ORDERLIST="0" /><VALUE MAP_ID="1005" MAP="1" MAPNAME="LostParadise" SERVER="1" CHNSERVER="1" NEEDLEVEL="7" TIME="0" WEATHER="0" VEHICLE="1" PVP="0" MINE="0" CONTROL="" ENTERLV="0" ENTERQUEST="0" ENTERITEM="0" NORECONNECT="0" MINIMAP="1002" VER="200" APPLY_ROW="0" MAP_EXP_RATIO="0" MAP_DROP_RATIO="0" MAP_MONEY_RATIO="0" ORDERLIST="0" />

我怎样才能实现这个目标?

答案1

这看起来像 XML,所以不要使用正则表达式要编辑它,请使用真正的 XML 解析器,例如xmlstarlet:

xml ed -u '//VALUE/@NORECONNECT' -v 0 file.xml

答案2

假设"该字段内没有嵌入字符,则可以使用类似的工具来完成sed

sed 's/NORECONNECT="[^"]*"/NORECONNECT="0"/'

第一个表达式表示匹配NORECONNECT=",后跟零个或多个非"字符,后跟"

所以这将匹配类似的东西

NORECONNECT="foo"
NORECONENCT="bar"
NORECONNECT=""

然后用字符串替换该部分

NORECONNECT="0"

编辑:

如果该单词在一行中出现多次,则g在末尾添加一个:

sed 's/NORECONNECT="[^"]*"/NORECONNECT="0"/g'

相关内容