Skip to main content
5 of 8
deleted 18 characters in body
user avatar
user avatar

Try with sort(1):

sort -rt';' filename | sort -t';' -usk1,1 Aerial Assault (USA);Aerial Assault (USA);Sega Master System;;1990;Sega;Shooter;;;;;0;;;;; After Burner (World);After Burner (World);Sega Master System;;1988;Sega;Flying;;;;;0;;;;; Air Rescue (Europe);Air Rescue (Europe);Sega Master System;;1992;Sega;Shooter;;;;;0;;;;; Aladdin (Europe);Aladdin (Europe);Sega Master System;;1994;Sega;Platform;;;;;0;;;;; 

Both sorts will use the ; as the field delimiter (-t';'). The first will reverse sort (-r), so that the empty fields come after the non-empty fields, and the second sort will sort by the first field (-k1,1), and remove lines with the same first field (-u = uniq), but will otherwise keep to order set by the first sort (-s = stable).

If you want to do it on a batch of files, you should use find:

find dir -type f -name '*.txt' \ -exec sh -c 'for f; do sort -rt";" "$f" | sort -t";" -usk1,1 > "$f.new" && echo mv "$f.new" "$f"; done' sh {} + 

Adjust the find's predicates (-name, etc) and only remove the echo from before mv if you're ready to clobber your existing files.

user313992