Skip to content

Instantly share code, notes, and snippets.

@noqqe
Last active December 29, 2015 04:19
Show Gist options
  • Save noqqe/7613657 to your computer and use it in GitHub Desktop.
Save noqqe/7613657 to your computer and use it in GitHub Desktop.
Converts categories from octopress header to tags in acrylamid (see example diff)
#!/bin/bash
# regex
HEADER="^---"
ITEM="^- "
FIELD="^categories:"
# initialize vars
ITEMLIST=""
DEL=()
LC=0
HC=0
# sanity
if [ ! -e "$1" ]; then
exit 1
fi
# runtime
while read line; do
# increase linecounter
((LC++))
# quit if header end is reached
if [ $HC -ge 2 ]; then
break
fi
# detect header
if [[ "$line" =~ $HEADER ]]; then
HC=$((HC+1))
fi
# detect categories field
if [[ "$line" =~ $FIELD ]]; then
CL=$LC
fi
# parse category item
if [[ "$line" =~ $ITEM ]] && [ $HC -lt 2 ]; then
ITEMLIST="$ITEMLIST, ${line#- }"
DEL+=($LC)
fi
done < $1
# replace FIELD with "tags: [ tag1, tag2 ]"
sed -i "${CL}s#.*#tags: [${ITEMLIST##,}]#" $1
# cleanup old category lines
F=${DEL[0]}
T=${DEL[${#DEL[@]} - 1]}
sed -i "${F},${T}d" $1
---
date: '2010-07-24 15:07:54'
layout: post
slug: mysql-datenbanken-einzeln-sichern
status: publish
comments: true
title: MySQL | Datenbanken einzeln sichern
-categories:
-- Coding
-- Debian
-- Linux
-- PlanetenBlogger
-- SQL
-- backup
-- mysql
-- single file
-- sql
+tags: [ Coding, Debian, Linux, PlanetenBlogger, SQL, backup, mysql, single file, sql]
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment