View Single Post
  #4   (View Single Post)  
Old 12th December 2008
sverreh's Avatar
sverreh sverreh is offline
Real Name: Sverre Hval
Port Guard
 
Join Date: Apr 2008
Location: Norway
Posts: 36
Default

Quote:
Originally Posted by J65nko View Post
How does vils handle spaces in file names?
Never tried that before, so let's test.

Code:
 % vils

  1 0001 last_pkg
  2 0002 last_pkg-calyx
  3 0003 latest_pkg-erlangen
  4 0004 latest_pkg-esat
  5 0005 latest_pkg-plig
  6 0006 latest_pkg-stacken

:%s/_/ /  1 0001 last pkg
  2 0002 last pkg-calyx
  3 0003 latest pkg-erlangen
  4 0004 latest pkg-esat
  5 0005 latest pkg-plig
  6 0006 latest pkg-stacken
:wq
sverre % ls
last pkg                latest pkg-erlangen     latest pkg-plig
last pkg-calyx          latest pkg-esat         latest pkg-stacken
sverre %
So creating file names with blanks seems to work. Now let's see what happens when we try to reinsert the underscore:

Code:
vils
  1 0001 last pkg
  2 0002 last pkg-calyx
  3 0003 latest pkg-erlangen
  4 0004 latest pkg-esat
  5 0005 latest pkg-plig
  6 0006 latest pkg-stacken
:%s/ /_/ 
  1 0001_last pkg
  2 0002_last pkg-calyx
  3 0003_latest pkg-erlangen
  4 0004_latest pkg-esat
  5 0005_latest pkg-plig
  6 0006_latest pkg-stacken
Ooops! Not exactly what we wanted We undo the change by typing u (we are actually working in vi here) and continue:

Code:
 
  1 0001 last pkg
  2 0002 last pkg-calyx
  3 0003 latest pkg-erlangen
  4 0004 latest pkg-esat
  5 0005 latest pkg-plig
  6 0006 latest pkg-stacken
:%s/\([A-z]\) /\1_/
  1 0001 last_pkg
  2 0002 last_pkg-calyx
  3 0003 latest_pkg-erlangen
  4 0004 latest_pkg-esat
  5 0005 latest_pkg-plig
  6 0006 latest_pkg-stacken
:wq
sverre % ls
last_pkg                latest_pkg-erlangen     latest_pkg-plig
last_pkg-calyx          latest_pkg-esat         latest_pkg-stacken
sverre %
~
Yes, it can be done, but requires some use of "leaning toothpicks". However, I don't think that scares you!

Of course, since we are actually editing the file names in vi, we could also replace each blank with an underscore manually, or by using the command:

Code:
:%s/ /_/gc
but that is not so interesting. (But I could have done it faster that way.) That's life
Reply With Quote