Skip to content

Instantly share code, notes, and snippets.

@budparr

budparr/csplit.txt

Last active Sep 28, 2018
Embed
What would you like to do?
Terminal command to split a list of markdown items into separate documents. Given a "slug" value, the file will be named that. You could also change slug to title and create slugs/filenames from the title. You may also want to run your output through a markdown converter, like https://github.com/domchristie/to-markdown
csplit -k -n 3 export.txt '/^@@@/' {'999'}; for i in xx*; do sed -i '' 's/@@@/---/g' $i; done; for i in xx*; do mv $i `egrep -m1 -e 'slug:.*' $i | sed -e s/[^\]\[A-Za-z0-9~.,_{}\(\)\'\-\+]/-/g -e s/slug--//`.md; done
---
layout: empty
description: "this is a sample file for outputting content to be split with the CSPLIT command. Note the '@@@' at the top.
---
{% assign data = site.data.events %}
{% for object in data %}
@@@<br />
title:{% if object.title %} "{{ object.title }}"{% endif %}<br />
published: true<br />
category: event<br />
start_at:{% if object.date %} {{ object.date | date: '%Y-%m-%d' }}T{% if object.start %}{{ object.start | date: '%k:%M' }}{% else %}00:00{% endif %}:00.000Z{% endif %}<br />
allday:{% if object.allday %} true{% else %} false{% endif %}<br />
venue:{% if object.venue %} "{{ object.venue }}"{% endif %}<br />
address:{% if object.address %} "{{ object.address }}"{% endif %}<br />
city-state:{% if object.city-state %} "{{ object.city-state }}"{% endif %}<br />
zip:{% if object.zip %} "{{ object.zip }}"{% endif %}<br />
website:{% if object.website %} "{{ object.website }}"{% endif %}<br />
slug: {% if object.date %}{{ object.date | date: '%Y-%m-%d' }}{% if object.title %}-{{ object.title | slugify }}{% else %}-event{% endif %}{% endif %}<br />
---<br />
{% if object.summary %}
{{ object.summary }}<br /><br />
{% endif %}
<br />
{% endfor %}
<br />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.