Skip to content

Instantly share code, notes, and snippets.

@CatTail
Created August 6, 2013 15:20
Show Gist options
  • Select an option

  • Save CatTail/6165444 to your computer and use it in GitHub Desktop.

Select an option

Save CatTail/6165444 to your computer and use it in GitHub Desktop.
A simple csv(comma seperated) to markdown translator.
#! /bin/bash
occur=$(head -n 1 $1 | grep -o "," | wc -l)
sep=" --- |"
seperator=""
for ((i=0; i<$occur; i++))
do
seperator+=$sep
done
lineno=0
file=''
for line in $(cat $1 | sed -e 's/,/|/g')
do
lineno=$((++lineno))
if [[ $lineno -eq 2 ]]
then
file+="$seperator\n"
fi
file+="$line\n"
done
printf "$file"
#cat $1 | sed -e 's/,/|/g' | sed -e "2i'${seperator}'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment