You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将CSV文件转换为对应层级结构的markdown大纲文件?

方法1:Python通用实现

无需安装额外依赖,直接用系统自带的Python环境就能运行:

last_h1 = None
# 替换成你自己的CSV文件路径
with open("data.csv", "r", encoding="utf-8") as f:
    # 跳过第一行表头
    next(f)
    for line in f:
        line = line.strip()
        if not line:
            continue
        # 按空白分割列
        _, h1, h2, x = line.split()
        # 只有h1更新时才输出一级标题
        if h1 != last_h1:
            print(f"# {h1}")
            last_h1 = h1
        # 输出二级标题和对应内容
        print(f"## {h2}")
        print(x)

运行后把输出重定向到文件即可得到目标Markdown:python convert.py > result.md


方法2:awk一行命令实现

Linux、macOS或者安装了WSL/Git Bash的Windows用户可以直接在终端执行:

awk 'NR>1 {if($2!=pre) {print "# "$2; pre=$2} print "## "$3; print $4}' data.csv > result.md

内容的提问来源于stack exchange,提问作者sbac

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 16:36:04