I want to change port in following input file:
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>SSH</short>
<port protocol="tcp" port="22"/>
</service>
I tried following command without success:
sed "s|\("^[[:space:]]*.+port[[:space:]]+protocol=.+port="\).*|\1\"3022\"\/>|" inputfile
but it does no change.
When I grep -E it return correct line and high-light correct matching:
# grep -E '^[[:space:]]*.+port[[:space:]]+protocol=.+port=' inputfile
<port protocol="tcp" port="22"/>
Why sed does not do the job?
Update: I found another command to achieve this:
sed -E '/short/,/service/ s/port=[^<]*/port=\"3022\"\/>/' inputfile