Below is an extract from xml. Here the pattern of the tags is not uniform.
i.e., For user A --> name,id,add isthe series
For user B --> id,name,add is the series
The sort command cannot exactly sort on a field with different > and < delimiters and variable field length, but the following produces a consistent order:
sort -t '>' -k2 file
or
sort -t '>' -k2r file
---------- Post updated at 03:42 PM ---------- Previous update was at 03:34 PM ----------
The following does exactly what you want.
sed changes the first > to a <
then sort works on a < delimited field
then sed changes the (2nd) < back to a >
sed 's/>/</' file | sort -t '<' -k3,3 | sed 's/</>/2'