Linux insert <br> utility?

Discussion in 'HTML' started by wcb, Jun 18, 2005.

  1. wcb

    wcb Guest

    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.


    --

    When I shake my killfile, I can hear them buzzing!

    Cheerful Charlie
     
    wcb, Jun 18, 2005
    #1
    1. Advertising

  2. in alt.html, wcb wrote:
    > 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...)

    --
    Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
    Utrecht, NL.
    Support me, buy Opera:
    https://secure.bmtmicro.com/opera/buy-opera.html?AID=882173
     
    Lauri Raittila, Jun 18, 2005
    #2
    1. Advertising

  3. wcb wrote:

    > 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?


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

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Jun 18, 2005
    #3
  4. wcb

    wcb Guest

    David Dorward wrote:

    > wcb wrote:
    >
    >> 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?

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


    Thank you.

    --

    When I shake my killfile, I can hear them buzzing!

    Cheerful Charlie
     
    wcb, Jun 18, 2005
    #4
  5. wcb

    Dan Guest

    wcb wrote:
    > 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.

    --
    Dan
     
    Dan, Jun 18, 2005
    #5
  6. wcb

    wcb Guest

    David Dorward wrote:

    > wcb wrote:
    >
    >> 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?

    >
    > 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.




    --

    When I shake my killfile, I can hear them buzzing!

    Cheerful Charlie
     
    wcb, Jun 18, 2005
    #6
  7. wcb

    wcb Guest

    Dan wrote:

    > wcb wrote:
    >> 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.
    >


    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.







    --

    When I shake my killfile, I can hear them buzzing!

    Cheerful Charlie
     
    wcb, Jun 18, 2005
    #7
  8. wcb wrote:

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


    > 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

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Jun 18, 2005
    #8
  9. wcb wrote:

    > 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.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Jun 18, 2005
    #9
  10. WCB wrote:

    >> You might want to take a look at Markdown.


    > Thanks but it seems to be Apple software.


    No, its just Perl. The author uses OS X, that's all.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Jun 19, 2005
    #10
  11. wcb

    WCB Guest

    David Dorward wrote:

    > wcb wrote:
    >
    >> 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.
    >


    Thanks but it seems to be Apple software.

    --
    When I shake my killfile I can hear them buzzing.
     
    WCB, Jun 19, 2005
    #11
  12. wcb

    WCB Guest

    Lauri Raittila wrote:

    > in alt.html, wcb wrote:
    >> 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...)


    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.
    --
    When I shake my killfile I can hear them buzzing.
     
    WCB, Jun 19, 2005
    #12
  13. WCB wrote:

    > Ohhh this would be so easy if Perl had a -R switch.


    find /start/directory -name \*.txt | xargs perl -i.bak -p -n -e
    's/\n/<br>\n/'


    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Jun 19, 2005
    #13
  14. in alt.html, WCB wrote:
    > Lauri Raittila wrote:
    >
    > > in alt.html, wcb wrote:
    > >> 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...)

    >
    > 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.

    --
    Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
    Utrecht, NL.
    Support me, buy Opera:
    https://secure.bmtmicro.com/opera/buy-opera.html?AID=882173
     
    Lauri Raittila, Jun 19, 2005
    #14
  15. wcb

    WCB Guest

    Lauri Raittila wrote:

    > in alt.html, WCB wrote:
    >> Lauri Raittila wrote:
    >>
    >> > in alt.html, wcb wrote:
    >> >> 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...)

    >>
    >> 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.
    >


    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.

    --
    When I shake my killfile I can hear them buzzing.
     
    WCB, Jun 20, 2005
    #15
  16. in alt.html, WCB wrote:
    > Lauri Raittila wrote:

    [lots of stuff snipped, please snip in future]

    > >> 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.


    > 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.


    --
    Lauri Raittila <http://www.iki.fi/lr> <http://www.iki.fi/zwak/fonts>
    Utrecht, NL.
    Support me, buy Opera:
    https://secure.bmtmicro.com/opera/buy-opera.html?AID=882173
     
    Lauri Raittila, Jun 20, 2005
    #16
  17. wcb

    WCB Guest

    Lauri Raittila wrote:

    > in alt.html, WCB wrote:
    >> Lauri Raittila wrote:

    > [lots of stuff snipped, please snip in future]
    >
    >> >> 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.

    >
    >> 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.

    >> 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.
    >


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


    >> 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.


    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.

    >
    >


    --
    When I shake my killfile I can hear them buzzing.
     
    WCB, Jun 20, 2005
    #17
  18. wcb

    JDS Guest

    On Sat, 18 Jun 2005 05:44:30 -0500, wcb wrote:

    >
    > 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

    --
    JDS | lid
    | http://www.newtnotes.com
    DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/
     
    JDS, Jun 20, 2005
    #18
  19. wcb

    JDS Guest

    On Sat, 18 Jun 2005 20:05:48 +0100, David Dorward wrote:

    > 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

    --
    JDS | lid
    | http://www.newtnotes.com
    DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/
     
    JDS, Jun 20, 2005
    #19
  20. wcb

    JDS Guest

    On Sun, 19 Jun 2005 07:02:14 -0500, WCB wrote:

    > 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...

    --
    JDS | lid
    | http://www.newtnotes.com
    DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/
     
    JDS, Jun 20, 2005
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cannontrodder
    Replies:
    1
    Views:
    764
    cannontrodder
    Jul 25, 2006
  2. Replies:
    1
    Views:
    479
  3. Replies:
    1
    Views:
    1,873
    Albert Hopkins
    Dec 6, 2008
  4. hiral
    Replies:
    0
    Views:
    316
    hiral
    Mar 12, 2010
  5. Replies:
    13
    Views:
    217
    Ed Morton
    May 20, 2011
Loading...

Share This Page