Wednesday, August 28, 2013

Unix sed: Modify xml file or move characters around

Following example can be used when we want to move characters around in the file based on xml tags or other character prefixes.

I wanted to remove sequencenumber tag along with value within tags from following line. I also wanted to move tags salary and suffix to first position after begin.

101886122arpit23452345shah116056III

Following script can help:
$ sed 's:\(\)\(.*\)\(.*last>\)\(.*suffix>\)\(.*\):\1\4\3\5:' a


116056IIIarpit23452345shah