linux - How can I remove and replace specific field value by name instead of fix column -
i want replace , remove substring text file line line. info want change under specific field. example, have following text:
{name:x, version:1.0, info:"test", ...} {name:y, version:0.1, info:"test again", ...} {name:z, version:1.1, info:"test over", ...} {name:x, info: "test", ..., version:1.2, ...}
the field in random order. want remove version value , replace info value specific string, "foo".
the expect result:
{name:x, info:"foo", ...} {name:y, info:"foo", ...} {name:z, info:"foo", ...} {name:x, info:"foo", ...}
is there smart way shell script? have no idea how replace substring above?
i know stupid command as
sed 's/info:\([^,}]*\)/info:\"foo\"/' file sed 's/version:\([^,}]*\)//' file
sed 's/\(version:[^,}]*,\)*\(.*\)info:[^,}]*\(,\{0,1}\)\(.*\)\(, *version:[^,}]*,\)*/\2info:"foo"\3\4/' file
(not tested) should trick (--posix
gnu sed)
Comments
Post a Comment