Jump to content


Photo

SOLVED: Help with a bash script


  • Please log in to reply
2 replies to this topic

#1 ninja_girl

ninja_girl

    Young Padawan

  • Members
  • Pip
  • 19 posts
  • Gender:Female

Posted 28 March 2009 - 04:26 AM

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.

Edited by ninja_girl, 29 March 2009 - 12:36 PM.


#2 rc69

rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 05 April 2009 - 11:59 PM

Care to post the solution so others can see what you did?

Edited by rc69, 05 April 2009 - 11:59 PM.


#3 ninja_girl

ninja_girl

    Young Padawan

  • Members
  • Pip
  • 19 posts
  • Gender:Female

Posted 06 May 2009 - 03:32 AM

Okay, here is the part of the 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
   }'

Edited by ninja_girl, 06 May 2009 - 03:33 AM.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users