Dear wakereh,
here is a script and two sets of files for what you want to do.
Best regards,
Axel
a.rb (966 Bytes)
a.txt (101 Bytes)
b.txt (201 Bytes)