Rearrange content of a file

Posted by VikJES on Super User See other posts from Super User or by VikJES
Published on 2013-10-17T12:39:23Z Indexed on 2013/10/18 10:01 UTC
Read the original article Hit count: 159

Filed under:
|

I'd like to rearrange the content of a file on a per line basis (see below), ideally without using Perl or Python (I'm not allowed to... Don't ask.)

The input file contains unordered header lines and lines with backup operation results. The output files should contain the lines ordered as shown below.

Original file:

Completed Backups
Backups with Warnings
Failed Backups
Server A backup was completed with warnings
Server B backup was successful
Server C backup failed
Server D backup was completed with warnings

End result:

Completed Backups
Server B backup was successful
Backups with Warnings
Server A backup was completed with warnings
Server D backup was completed with warnings
Failed Backups
Server C backup failed

© Super User or respective owner

Related posts about linux

Related posts about shell-script