If you try to copy the plain text pukiwiki source files from one wiki to another, you might notice that they are named with some sort of hash key code, like 50756B6957696B69.txt
PukiWiki was developed in japan, so in order to support filenames with japanese characters more easily, all filenames were encoded as hexadecimal pairs for the value of each character, i guess. Anyway, here are some useful scripts to convert from hex pair to ascii:
hexpair_to_ascii
#!/bin/bash SUFFIX=".txt" string=${1%$SUFFIX} #printf "$string\n" for ((i=0; i<${#string}; i=$i+2)) do CHAR=${string:$i:2} printf "\x$CHAR" done printf "$SUFFIX\n"
ascii_to_hexpair
#!/bin/bash SUFFIX=".txt" string=${1%$SUFFIX} for ((i=0; i<${#string}; ++i)) do CHAR=${string:$i:1} printf "%X" "'$CHAR" done printf "$SUFFIX\n"
to use these scripts you need to cd to the wiki/ directory and do something like,
mkdir ascii; for i in `ls *.txt` ; do cp $i "ascii/`./hexpair_to_ascii $i`" ; done
this will convert your files into readable filenames, so you can sort through and get the ones you want. there will be some whining about "no such directory" for the files that start with 3A but you probably dont want those files anyway, and the foo required to make all those /'s work correctly isn't worth it right now. Next, you need to convert back to hex-pair-encoded filenames so that pukiwiki will recognize them, with
mkdir hexpair; for i in `ls *.txt` ; do cp $i "hexpair/`./ascii_to_hexpair $i`" ; done
Now just dump all those weird filenames into your pukiwiki wiki/ directory.
This trick can be used to import "attach" files such as images or .pdf files as well, just change the suffix and dump them in the attach/ directory. Hope you enjoyed this installment of "scripting with bash", tune in next week for an exciting foray into window manager customization!