[pmwiki-users] wiki page creation

Jens jens at quefaire.de
Sun Mar 23 13:27:39 CDT 2008


Hans wrote:

> Is there an easy way to automatically create a bunch of
> wiki pages from a text file, which consists of a list of sections,
> and each section shall become a new wiki page?
> 
> The sections are mainly of plain text with some wiki markup,
> the beginning of each section is determined by some text marker
> string, the end of each section by the beginning of the next.
> The wiki page name needs to be determined by a string in each section.

I'd recommend using gnu awk.

Let's assume every section starts with a line like "=== PageName ===".

Save the following awk script to a text file (eg. txt2pmwiki.awk)
and at the shell prompt enter

#> mkdir my-wiki.d
#> cd my-wiki.d
#> awk -f ../txt2pmwiki.awk ../mytextfile.txt


----- snip -----
# txt2pmwiki.awk
#
# purpose:
#   create pmwiki page files from a single text file
#
# first line of section pattern
#   write previous page file
#   caution: will overwrite file "OUTFILENAME" in current dir
#
#   read next pagename
#
#!TODO: adjust line pattern to your needs
#
/^===.*===$/ {
   if ( OUTFILENAME > "" )
   {
     print OUT > OUTFILENAME;
   }

   # extract page name
   #
   #!TODO: adjust pattern
   #
   OUTFILENAME = $0;
   gsub("===", "", OUTFILENAME); # strip dashes
   gsub("[[:space:]]+", "", OUTFILENAME); # strip whitespace

   OUT = "version=pmwiki-2.1.3 ordered=1 urlencoded=1\ntext=" ;

   next ; # proceed with next line of input file
}
#
# otherwise (NOT first line of section pattern)
#   combine all input lines to a single output string
{
   # replace percent sign with url encoded equivalent
   gsub("%", "%25" , $0) ;
   # append line to output, line separator is %0a
   OUT = OUT "%0a" $0 ;
}

#
# at end of input file
#   write last page file
#   caution: will overwrite file "OUTFILENAME" in current dir
END {
  if ( OUTFILENAME > "" )
  {
     print OUT > OUTFILENAME;
  }
}
----- snap -----
> 
> I work on a Windows PC.

Then youll need a windows port of the gnu utilities. It can be found at 
http://unxutils.sourceforge.net/



Jens



More information about the pmwiki-users mailing list