I recently had the need to cleanup a long diff file and move certain lines to the end of the file for further analysis. The diff file that I got was something like the following, only much longer (produced using diff -qr xxx yyy
).
Files xxx/abc1 and yyy/abc1 differ Only in xxx: cde1 Files xxx/abc3 and yyy/abc3 differ Files xxx/abc4 and yyy/abc4 differ Only in xxx: cde2 Only in xxx: cde5 Files xxx/abc5 and yyy/abc5 differ Only in xxx: cde3
I didn’t care as much about the “Only…” lines, but the files that differed needed more attention. To accomplish this I wanted to get this file in the following format.
Only in xxx: cde1 Only in xxx: cde2 Only in xxx: cde5 Only in xxx: cde3 Files xxx/abc1 and yyy/abc1 differ Files xxx/abc3 and yyy/abc3 differ Files xxx/abc4 and yyy/abc4 differ Files xxx/abc5 and yyy/abc5 differ
I could go in and copy and paste all the lines that matched, but that would be a lot of manual work. So, I looked around for a minute and came up with the following command.
:%g/^Files/m$
Vim is awesome!