Create a struct or class that holds the information from the three lines.
Read the file into a deque of those structures.
Use the sort algorithm (#include <algorithm>) with a custom sort function to sort the deque.
Write the deque of structures back out to the file (overwrite it).
Hope this helps.
You could create a struct to contain your lines of data and then read your file into a std::map using the first line as the key. That will order your structs alphabetically according to the names. Then just write the data out to a new file using a std::map::iterator.
This is obviously quick-and-dirty and assumes that there are no pipes in the input file, but it gets the job done without having to pull out the big C++ hammer. If you plan on reuse, then coding it up in C++ may be a better choice.
But if you just want to get the job done, there are a myriad of choices from UNIX one-liners to perl or Ruby or python. All these scripting languages are actually very decent choices for text processing, in most cases.
input.txt
name3
Random Line 3.1
ABCDEFG 3.2
hijklmn 3.3
name9
FirstLineOf 9.1
ZYX 9.2
ABC 9.3
name2
2.1
2.2
2.3
output
name2
2.1
2.2
2.3
name3
Random Line 3.1
ABCDEFG 3.2
hijklmn 3.3
name9
FirstLineOf 9.1
ZYX 9.2
ABC 9.3