Help - Search - Members - Calendar
Full Version: SOLVED: Help with a bash script
Pixel2Life Forum > Help Section > Desktop Programming
ninja_girl
Hello,
I'm writing my first bash script and I already have it mostly done except for this. My task is to convert a text file into a html.

I need to replace '@ ' with an unordered list <ul> and following items in <li></li>, like this:

@ Item
@ Item
@ Item
to

<ul>
<li>Item</li>
<li>Item</li>
<li>Item</li>
</ul>


SOLVED this on my own, you can delete this thread.
rc69
Care to post the solution so others can see what you did?
ninja_girl
Okay, here is the part of the code:

CODE
   *for every line starting with '@ '
   /^  \@ /{
   # adds tag <ul>
   i\
   <ul>
   # exchange '@ ' for <li>
   s!^  \* \(.*\)$!<li>\1</li>!
   # adds tag </ul>
   a\
   </ul>
   }
  
   # if there was a change in the file, jump to 'end'
   t end
   # else switch <br/> for line end
   s!$!<br/>!  
  
   : end
   * adds html footer at the end of file
   * if there's </ul><ul> under each other, delete the </ul>
   $a\
   </body></html>' | sed '/<\/ul>/{
   N
   /<ul>/d
   }'
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.