Description
Given a datafile where each line of it is a file path.
We want to convert that file to a sequence of FTP `put' commands to upload them.
Instead of just `put'ting them directly,
if a bunch of files are to be uploaded to the same directory,
we want to
- `cd' to that directory first,
- then each `put' each one of them with only the basenames, without
the directory part.
Besides,
- Each line of the datafile begins with ./.
- To `cd' to another directory, a relative path is used.
|
| Raw Input
|
| Desired Output
| ./top/index.html
./top/lecture1.html
./top/lecture2.html
./pr1/sub1/slide1.html
./pr1/sub1/slide2.html
./pr1/sub2/slide1.html
./pr1/sub3/sub31/slide1.html
./pr2/slide1.html
./pr2/slide2.html
|
| cd ./top
put index.html
put lecture1.html
put lecture2.html
cd ./../pr1/sub1
put slide1.html
put slide2.html
cd ./../../pr1/sub2
put slide1.html
cd ./../../pr1/sub3/sub31
put slide1.html
cd ./../../../pr2
put slide1.html
put slide2.html
|
|
Script and Comments
Script1 [ 1] G
[ 2] /^\.((\/[^/\n]+)*)\/[^\n]+\n\.\1\/[^/]+$/{
[ 3] s/\n.*//
[ 4] h
[ 5] s/^.*\//put /
[ 6] b
[ 7] }
[ 8] h
[ 9] s/\n.*//
[10] x
[11] s/\n\.?/ \n/
[12] :loop
[13] s/\n\/[^/]+\//\/..\n\//
[14] /\n\/.*\//b loop
[15] s/^\.((\/[^/]+)*)\/([^\n]+) ([^\n]*)\n.*/cd .\4\1\nput \3/
| |
|