diff options
author | Ben Sima <ben@bensima.com> | 2025-05-01 11:46:16 -0400 |
---|---|---|
committer | Ben Sima <ben@bensima.com> | 2025-05-01 11:46:40 -0400 |
commit | 168ebb4dc55d92c5c91a343e6790e75165b43cf6 (patch) | |
tree | beb349c8e70a3c66457ec9f4b06bec19a5b4df1e /csv2md | |
parent | d4a9d5b0b3a3d26fb283c6a1318061bf97c90bbd (diff) |
add csv2md script
Diffstat (limited to 'csv2md')
-rwxr-xr-x | csv2md | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -0,0 +1,21 @@ +#!/usr/bin/env python3 +# csv2md - Convert CSV to Markdown table +import csv +import fileinput +import sys + +# Read from stdin or file specified as argument +csv_data = ''.join(line for line in fileinput.input()) +reader = csv.reader(csv_data.splitlines()) +rows = list(reader) + +if rows: + # Print header row + print(f"| {' | '.join(rows[0])} |") + + # Print separator row + print(f"| {' | '.join(['---'] * len(rows[0]))} |") + + # Print data rows + for row in rows[1:]: + print(f"| {' | '.join(row)} |") |