[PLUG] tree to html
Paul Heinlein
heinlein at attbi.com
Fri Dec 13 22:46:53 UTC 2002
On Fri, 13 Dec 2002, Kyle Accardi wrote:
> for f in "$(find . | sort)"; do
> echo "$f" | sed -e 's![^/]\+/!\ \ !g' -e 's!$!<br>!'
> done
>
> perhaps you could help me grok the sed command, though
>
> you're substituting everything before a / with   and
> tacking <br> to the end, but my reference doesn't talk about the
> plus sign. Is that to indicate multiple substitutions?
sed -e 's![^/]\+/!\ \ !g'
My Rosetta Stone, where C == command line, E == English translation of
command line, and N == misc. notes.
C: sed -e
E: Hey, sed. I need you to do something for me.
C: 's!!!'
E: I'd like you to do some text substitution for me.
N: Perl just stole this notation, since it was familiar to sed-ites.
C: [^/]\+/
E: Look for one or more characters (excluding a forward slash) that
are followed by a forward slash.
N: The '+' isn't universally honored by all sed implementations. I
know that Sun's sed can't grok it. GNU sed might be unique. In
fact, now that I look through the sed texinfo and man pages, I
see that the '+' isn't even documented. Wierd. I guess I at some
point extrapolated from, e.g., the expr syntax.
C: \ \
E: Replace that text with " ".
N: The & needs to be escaped lest sed interpret it as what the
sed(1) man page calls "the special character &" that refers
"to that portion of the pattern space which matched."
C: g
E: Do that replacement as often as you can on the text you're
reading.
> And the bangs don't jibe with my book which says "applies the
> command to all lines except the selected ones".
The bangs are just separators for the s/// command; I could just as
easily have used commas, slashes, carats, hashes, or what-have-you. I
like exclamation marks because I rarely have them in the text I'm
matching, unlike forward slashes, which occur all the time in
filenames.
--Paul Heinlein <heinlein at attbi.com>
More information about the PLUG
mailing list