As @Naga mentioned in the comments that a Ruby script is allowed. Here I have came up with a solution.
Ruby Script
#!/usr/bin/env ruby
# Frozen_String_Literal: false
$-v = nil
d, $-s, i, $,, $; = [], ?\s.freeze, '', ?:.freeze, ?:.freeze
::FILENAME = $*[0] || abort("Pass the filename as Argument.\nExample:\n\t#{File.basename($0)} hello.rb")
puts IO.readlines(File.join(Dir.pwd, FILENAME)).map! { |x|
c = x.tap(&:strip!).split
d.clear && i.replace(c[0].to_s) if i != c[0]
a = c.first(2).map { |y| d.find { |z| z.include?(y) } ? $-s : y }.join << $, << c.drop(2).join unless c.empty?
d << c.first(2).join
a
} rescue exit!
Running
ruby scriptname.rb inputfile.txt
Output
[Assuming inputfile.txt contains the same data in the question]
1:x:4:3:2:y
: :7:9:l:z
:0:3:j:k:m
2:9:r:s:6:u
:m:y:5:7:9
:u:7:9:7:6
3:a:b:c:d:e
: :b:d:e:f
: :b:n:r:s
Hope this helps!
xin column 2 in a line further down also be deleted?