Como eu disse no meu comentário, não entendi qual é a sua pergunta real. Aqui estão algumas maneiras mais concisas de fazer o que seu script sed
faz:
$ printf "%s\n%s\n\t%s\n%s\n%s\n%s\n" '<?xml version="1.0" encoding="utf-8"?>' \
'<hello>' '<world>' "$(cat file)" "</world>" "</hello>"
<?xml version="1.0" encoding="utf-8"?>
<hello>
<world>
<city id="city01">
<name>utrecht</author>
<population>328.577</population>
<districts>10</districts>
<country>netherlands</country>
</city>
</world>
</hello>
ou
$ echo -e '<?xml version="1.0" encoding="utf-8"?>' "\n<hello>\n<world>" "$(cat file)" \
"</world>\n</hello>"
<?xml version="1.0" encoding="utf-8"?>
<hello>
<world> <city id="city01">
<name>utrecht</author>
<population>328.577</population>
<districts>10</districts>
<country>netherlands</country>
</city> </world>
</hello>
ou
$ perl -lpe 'BEGIN{
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<hello>\n\t<world>"
}
$_="\t\t$_"; END{print "\t </world>\n</hello>"}' file
<?xml version="1.0" encoding="utf-8"?>
<hello>
<world>
<city id="city01">
<name>utrecht</author>
<population>328.577</population>
<districts>10</districts>
<country>netherlands</country>
</city>
</world>
</hello>
Você pode editar o arquivo com perl -i -ple
.
ou
$ awk 'BEGIN{printf "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<hello>\n\t<world>";}
{print "\t\t",$0}END{printf "\t </world>\n</hello>\n"}' file
<?xml version="1.0" encoding="utf-8"?>
<hello>
<world> <city id="city01">
<name>utrecht</author>
<population>328.577</population>
<districts>10</districts>
<country>netherlands</country>
</city>
</world>
</hello>
ou uma mistura:
$ echo -e '<?xml version="1.0" encoding="utf-8"?>\n<hello>\n\t<world>';
perl -pe '$_="\t\t$_"' file; echo -e "</world>\n</hello>"
<?xml version="1.0" encoding="utf-8"?>
<hello>
<world>
<city id="city01">
<name>utrecht</author>
<population>328.577</population>
<districts>10</districts>
<country>netherlands</country>
</city>
</world>
</hello>