Linux insert <br> utility?

W

wcb

I am using Linux and Bluefish.
I have a lot of long documents I want html-ize.
I am looking for some sort of little Linux utility
where I could insert <br>'s into an existing file.

Thus a long
dreary,
dusty,
document,
...
Like this,

Would be changed to

Thus a long<br>
dreary,<br>
dusty,<br>
document<br>
...<br>
Like this,<br>
<br>

Is there such a quick and dirty beastie for Linux?
Most utilities I see seem to be for Windows.
I am looking for something that can do batch
processing if possible, doing an entire folder
at one shot.
 
L

Lauri Raittila

I am using Linux and Bluefish.
I have a lot of long documents I want html-ize.

Learn perl.
I am looking for some sort of little Linux utility
where I could insert <br>'s into an existing file.
Is there such a quick and dirty beastie for Linux?

sed
man sed
Most utilities I see seem to be for Windows.

Because nobody needs any *extra* utilies for something that simple in
linux... there is some other tool as well, even more simple, but I don't
recall what it is called...
I am looking for something that can do batch
processing if possible, doing an entire folder
at one shot.

sed -i 's/$/<br>/g;' *.html
(if I got it right...)
 
D

Dan

wcb said:
I am using Linux and Bluefish.
I have a lot of long documents I want html-ize.
I am looking for some sort of little Linux utility
where I could insert <br>'s into an existing file.

Though, if you're looking for a more logically structured final
document, you might prefer to use other tags, such as <p>, where
appropriate, so the paragraphs and other structural elements are
properly marked.
 
W

wcb

David said:
perl -i.bak -p -n -e 's/\n/<br>\n/' myTextFile

OK, this didn't quite work.

I rewrote it perl -p -e 's/\n/<br>\n/' myfile > myfile.br
Which does. It slaps <br> like I wanted and pipes it to
a new file with a .br on the end of the file's name.

But if I try * > *.br in a directory with numerous files,
it does not work, perl does not understand *. What's the
magic tickle for perl here that would allow a batch process?
What does perl use instead of "*" ? "Learning Perl" does not
have wild card in the index.
 
W

wcb

Dan said:
Though, if you're looking for a more logically structured final
document, you might prefer to use other tags, such as <p>, where
appropriate, so the paragraphs and other structural elements are
properly marked.

They're are already formatted, and I really need to get the <br>
tags in first. I want to keep most of it formated as is. There
are a lot of long files.
But with 300+ lines that's a lot of <br>ing to do by hand.
I may later have to tweak a few, but if I can get the bulk done
by batch processing it will save me a massive amount of work.

Each doc will be a html file and I'll use CSS to do most of
the rest.

It might be nice to give them better structure, but that
won't happen most likely until I can figure out enough Perl
to let Perl do most the heavy lifting.

I have my hands full figuring out HTML, CSS and HTML editors.
Three battles at a time is enough for now.
 
D

David Dorward

OK, this didn't quite work.

It did when I tested it. It modifies myTextFile, and creates a copy of the
original at myTextFile.bak.
I rewrote it perl -p -e 's/\n/<br>\n/' myfile > myfile.br
Which does. It slaps <br> like I wanted and pipes it to
a new file with a .br on the end of the file's name.
But if I try * > *.br in a directory with numerous files,
it does not work, perl does not understand *.

perl doesn't even see * - it is expanded by the shell before it gets to
perl. Using my original code:

perl -i.bak -p -n -e 's/\n/<br>\n/' *

.... works fine.

Using yours, the easiest way would probably be to wrap it in a shell script:

for x in *
do perl -p -e 's/\n/<br>\n/' $x > $x.br
done
 
D

David Dorward

wcb said:
It might be nice to give them better structure, but that
won't happen most likely until I can figure out enough Perl
to let Perl do most the heavy lifting.

You might want to take a look at Markdown. There probably isn't any need to
reinvent the wheel.
 
W

WCB

Lauri said:
Learn perl.



sed
man sed


Because nobody needs any *extra* utilies for something that simple in
linux... there is some other tool as well, even more simple, but I don't
recall what it is called...


sed -i 's/$/<br>/g;' *.html
(if I got it right...)

But it still lacks recursive abilities.
I played with SED a bit. It still seems
to need a script to walk a tree.


Generally, it seems I need a shell script and a command
script whether it be SED or Perl, or even Rexx.


for
some command
done

I need to figure this out for the present
directory, all subdirecties, and all
files in them.

I could set up the command as a script
and call that.

So its back to Bash manuals....

Ohhh this would be so easy if Perl had a -R switch.
Or Sed or Awk.
 
L

Lauri Raittila

But it still lacks recursive abilities.
I played with SED a bit. It still seems
to need a script to walk a tree.

man find

sed -i 's/$/<br>/g;' `find . -type f -iname \*.html`
or
find . -type f -iname \*.html -exec sed -i 's/$/<br>/g;' {} \;

Quite likely I got em wrong...
I need to figure this out for the present
directory, all subdirecties, and all
files in them.

Which you of course didn'tm mention orginally.
 
W

WCB

Lauri said:
man find

sed -i 's/$/<br>/g;' `find . -type f -iname \*.html`
or
find . -type f -iname \*.html -exec sed -i 's/$/<br>/g;' {} \;

Quite likely I got em wrong...


Which you of course didn'tm mention orginally.

I had hoped that would have been obvious.
One does not want to have to walk through hundreds
of subdirectories by hand.

I had thought somewhere on the web, I could find a repository of
the simple and general atomic, basic bits and pieces to get these
sorts of scripts written and working without having to reinvent
the wheel.

Amazing there is not. I can find bash or perl scripts to
create entire websites or create front ends for MySQL.

Nothing at all for a very basic walk a directory script.
Why does stuff like this always have to be so hard and time
consuming?

Its like, get this big thick book, study it a few weeks and
start reinventing all those useful little wheels.
Why, you have nothing but time for that right?
Welcome to the Linux/Unix world. We've all been doing it
the hard way for 35 years and we aren't going to stop now.
Perl is even worse.
 
L

Lauri Raittila

Lauri Raittila wrote:
[lots of stuff snipped, please snip in future]
I had hoped that would have been obvious.

Well, you didn't mention it, so I didn't give it a thought...
I had thought somewhere on the web, I could find a repository of
the simple and general atomic, basic bits and pieces to get these
sorts of scripts written and working without having to reinvent
the wheel.

There is. You just don't seem to find anything unless pointed.
Nothing at all for a very basic walk a directory script.

You are looking wrong place. I have found them easily enough. They are
not in script archives, they are examples in manuals or tutorials. After
all, those things are the very basic stuff.
Why does stuff like this always have to be so hard and time consuming?

Don't know.
Welcome to the Linux/Unix world. We've all been doing it
the hard way for 35 years and we aren't going to stop now.

Do you know why? Because "hard way" is so much more efficient than the
easy way. Describe how to do this job you wanted to do in windows using
one line? Ten lines? Might be possible using 100 lines...
Perl is even worse.

I learned enough perl to do a text file to webpage conversion faster than
I would have converted one text file. I don't know what is hard for you,
but I think you are looking in bad places.
 
W

WCB

Lauri said:
Lauri Raittila wrote:
[lots of stuff snipped, please snip in future]
I had hoped that would have been obvious.

Well, you didn't mention it, so I didn't give it a thought...
I had thought somewhere on the web, I could find a repository of
the simple and general atomic, basic bits and pieces to get these
sorts of scripts written and working without having to reinvent
the wheel.

There is. You just don't seem to find anything unless pointed.

I find lots of stuff. Just not what I am looking
for.
You are looking wrong place. I have found them easily enough. They are
not in script archives, they are examples in manuals or tutorials. After
all, those things are the very basic stuff.

I have lots of manuals and I don't find them there.

Don't know.


Do you know why? Because "hard way" is so much more efficient than the
easy way. Describe how to do this job you wanted to do in windows using
one line? Ten lines? Might be possible using 100 lines...


I learned enough perl to do a text file to webpage conversion faster than
I would have converted one text file. I don't know what is hard for you,
but I think you are looking in bad places.

I have a tack of boosk I desperately don't want to pore over ubntil I know
enough Perl to reinvent the wheel.

That is what I am faced with.

I am looking for wheels.
 
J

JDS

Is there such a quick and dirty beastie for Linux?
Most utilities I see seem to be for Windows.
I am looking for something that can do batch
processing if possible, doing an entire folder
at one shot.


perl one liner

perl -p -i -e 's/$/<br>/' filename
 
J

JDS

perl doesn't even see * - it is expanded by the shell before it gets to
perl. Using my original code:

perl -i.bak -p -n -e 's/\n/<br>\n/' *


Using the "-n" and "-p" flags is redundant. Use either -p or -n. In this
case, use -p, and NOT -n. (In fact, the "-p" flag overrides the "-n"
flag, and thus makes the two flags mutually exclusive)

See

perldoc perlrun


for more information
 
J

JDS

But it still lacks recursive abilities.
I played with SED a bit. It still seems
to need a script to walk a tree.

Use "find" combined with "perl" (if you are using a unixy OS)

find . -name "*html" -exec perl -p -i- e 's/$/<br>/' {} \;

later...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top