1---2title: 'Kobo - helper scripts'3date: '2010-05-29'4published_at: '2010-05-29T16:51:00.007+10:00'5tags: ['books', 'ebook', 'gadgets', 'kobo']6author: 'Gavin Jackson'7excerpt: 'Here are a couple of scripts that might help you out if you are a Kobo user trying to load third party eBooks. Script 1: strip out all style data (this fixes up the margins and any font issues that yo...'8updated_at: '2010-05-29T17:21:15.478+10:00'9legacy_url: 'http://www.gavinj.net/2010/05/kobo-helper-scripts.html'10---1112Here are a couple of scripts that might help you out if you are a Kobo user trying to load third party eBooks. Script 1: strip out all style data (this fixes up the margins and any font issues that you may be experiencing).1314Simply put the epub files you want to convert in the same directory as the script (tested on Mac OS 10.5 - but should work on all Unix variants).1516```17#!/bin/bash18mkdir _unpack19#iterate over each epub in this folder20find . -name '*.epub' -depth 1|while read epub21do22unzip "${epub}" -d ./_unpack23cd ./_unpack/OEBPS24for xhtml_file in `ls|grep xhtml`25do26awk '{gsub("", "");print}' "${xhtml_file}" > "${xhtml_file}.new"27mv "${xhtml_file}.new" "${xhtml_file}"28done29cd ../30echo `pwd`31mv "../${epub}" "../${epub}.old"32zip -r "../${epub}" *33cd ../34rm -rf _unpack35done36```3738Script 2: strip out all style data and load a jpg image for the book cover (note that both book and jpeg must be in a sub directory for this to work).3940```41#!/bin/bash42find . -type d -depth 1|while read dir43do44cd "${dir}"45mkdir _unpack46#iterate over each epub in this folder47find . -name '*.epub' -depth 1|while read epub48do49unzip "${epub}" -d ./_unpack5051cd ./_unpack/OEBPS52for xhtml_file in `ls|grep xhtml`53do54awk '{gsub("", "");print}' "${xhtml_file}" > "${xhtml_file}.new"55mv "${xhtml_file}.new" "${xhtml_file}"56done57cp ../../../title.xhtml ./58cp ../../*.jpg ./cover.jpg59cd ../60echo `pwd`61mv "../${epub}" "../${epub}.old"62zip -r "../${epub}" *63cd ../64rm -rf _unpack65done66cd ..67done68```6970The working directory must have the following title.xhtml file in it:71727374```7576```777879