Description
Given a line of the form p1: p2 p3 p4... where pi is a path containing a directory.
Each path except the first one is preceded by a blank.
The job is to remove the directory part and the suffix of every pi.
Raw Input
/fs/ext3/ext3.ko: /fs/jbd/jbd.ko
/drivers/ata/ata_piix.ko: /drivers/ata/libata.ko /drivers/scsi/scsi_mod.ko
Desired Output
ext3: jbd
ata_piix: libata scsi_mod
Script and Comments
Script1
[ 1] s#( |^)(/[^/ ]+)+/#\1#g
[ 2] s/\.ko//g
Comments
  1. The `-r' option of GNU sed must be used to make sed interpret REs as EREs.
  2. It seems that the ERE (/[^/]+)+/ will match the directory part of every path, but it will catch all characters up to the last slash(/) of that line, (/[^/ ]+)+/ must be used instead, which will not span across a blank.
  3. To removing the directory of every path including the first one, it will work to replace every string matched ( |^)(/[^/ ]+)+/ with the character captured by the first pair of parentheses. The corresponding command is s/( |^)(\/[^/ ]+)+\//\1/g.
    To make it readable, we can replace the default slash delimiter with some other character, e.g., '#', rendering s#( |^)(/[^/ ])+/#\1#g