How can i insert lines into a file using shell script such that they are inserted in alphabetical order, following would explain better.
input file contains :
1 hsdfd
2 bsdfd
3 ekksdf
.
.
i want to insert these contents into another file using shell script such that they are as below,sorted on the alphabetical order:
< root > <br>
< devices name="bsdfd" value=2 > <br>
< details info="xxxxxxxxxxxxxxxxx"> <br>
< details info="yyyyyyyyyyyyyyyyy"> <br>
< /devices > <br>
< devices name="ekksdf" value=3 > <br>
< details info="xxxxxxxxxxxxxxxxx"> <br>
< details info="yyyyyyyyyyyyyyyyy"> <br>
< /devices > <br>
< devices name="hsdfd" value=1 > <br>
< details info="xxxxxxxxxxxxxxxxx"> <br>
< details info="yyyyyyyyyyyyyyyyy"> <br>
< /devices > <br>
< /root>
So if there is a second file, and you want the result being sorted:
updated: After your edit, I would use sed for the main work, after invoking sort:
Some cosmetics with cat in the end, for footer and header. Done. 🙂