Thursday, May 20, 2010

Rough Sed and Awk Code to Convert a CSV file to a sortable Mediawiki table

echo -e "3,4,5,5\n4,5,6,8" | sed "s/$/\n-/" | sed -e "s/,/\n/g" | sed -e "s/^/|/" | awk 'BEGIN {
    print "{|class=\"wikitable sortable\" style=\"vertical-align:top; background:lightblue;\"\n!key value!!col 1!!col 2!!col 3\n|-"
    }
    {
    print
    }
    END {
    print "|}"
    }
  '