Description
Given a file name, we want to compose a command line based on it:
  • the command is 'ln',
  • the first argument is '-f',
  • the second one is the name translated from the file name by replacing every slash('/') with a dot('.'),
  • and the last one is the original file name.
Raw Input
foo/bar/dir1/blah.html
foobar/dir2/check.sh
Desired Output
ln -f foo/bar/dir1/blah.html foo.bar.dir1.blah.html
ln -f foobar/dir2/check.sh foobar.dir2.check.sh
Script and Comments
Script1
[ 1] h
[ 2] y/\//./
[ 3] H
[ 4] x
[ 5] s/^\(.*\)\n/ln -f \1 /
Comments
  1. The Pattern and the Hold Space are abbreviated to PS and HS, respectively.
  2. Step [1] is used to save a copy of the original file name to HS.
  3. Command 'y' of Step [2] is used to translate every slash in PS to a dot.
    After this, PS contains the translated file name.
  4. Command 'H' of Step [3] will append the translated name to the end of HS.
    After this, HS consists of original name \n translated name.
  5. Command 'x' of Step [4] will exchange the contents of PS and HS.
    After this, PS consists of original name \n translated name.
  6. Step [5] will prepend 'ln -f ' before the original name and translate the embedded newline character to a space.