注意:每个单元格不能出现字符【|、$、;】

1. bat文件里面写死文件名

@echo off && setlocal enabledelayedexpansion

SET mdfile=MD-CSV.md
SET csvfile=csv-md.csv :: 当前目录下创建文件
cd. >%csvfile% set /a index=0 set "nativesplit=|"
set "splitstr=$"
set "tmpsplit=,"
set end=0
set one=0
set "stepstr="
set "splitstrempty=$ "
set inforsum=30
set inforindex=0
set "teststring="
set "enter=;" for /f "delims=" %%a in (%mdfile%) do (
set "tmpstr="
set /a index+=1
set data1=%%a if !index! NEQ 2 (
if "!data1:~-1!"==" " (
set "data1=!data1:~0,-1!"
) set "data1=!data1:~1,-1!" set "teststring=!teststring!!enter!!data1!"
)
) set "teststring=!teststring:|=$!" :splitend
echo !teststring!| findstr !splitstrempty! >nul && (
set "teststring=!teststring:%splitstrempty%=%splitstr%!"
set /a inforindex+=1
if !inforindex! == !inforsum! (
set inforindex=0
goto splitstart
)
goto splitend
) || (
set inforindex=0
goto splitstart
) :splitstart
set "splitstrempty= $"
echo !teststring!| findstr !splitstrempty! >nul && (
set "teststring=!teststring:%splitstrempty%=%splitstr%!"
set /a inforindex+=1
if !inforindex! == !inforsum! (
set inforindex=0
goto headsplit
)
goto splitstart
) || (
set inforindex=0
goto headsplit
) :headsplit
set "teststring=!teststring:$=,!"
set teststring=!teststring:~1,-1!
echo !teststring! :stringLOOP
if "!teststring!" EQU "" (
goto END
) :: 注意:切割符号
for /f "delims=;" %%a in ("!teststring!") do (
set substring=%%a
)
if "!substring:~-1!"==" " (
set "substring=!substring:~0,-1!"
)
if "!substring:~-1!"==" " (
set "substring=!substring:~0,-1!"
)
if "!substring:~0,1!"==" " (
set "substring=!substring:~1!"
)
echo !substring!>>%csvfile% :striploop
set stripchar=!teststring:~0,1!
set teststring=!teststring:~1! :: 如果为空字符串,就结束
if "!teststring!" EQU "" (
goto END
) if "!stripchar!" NEQ "!enter!" (
set "substring="
goto striploop
) goto stringloop
) :END pause

2. 拖入文件

生成的csv文件格式为MD2CSV-MD文件名.csv

@echo off && setlocal enabledelayedexpansion

set nativemdfile=%~1
set mdfile=%~n1
SET "csvfile=MD2CSV-!mdfile!.csv" :: 当前目录下创建文件
cd. >%csvfile% set /a index=0 set "nativesplit=|"
set "splitstr=$"
set "tmpsplit=,"
set end=0
set one=0
set "stepstr="
set "splitstrempty=$ "
set inforsum=30
set inforindex=0
set "teststring="
set "enter=;" for /f "delims=" %%a in (%nativemdfile%) do (
set "tmpstr="
set /a index+=1
set data1=%%a if !index! NEQ 2 (
if "!data1:~-1!"==" " (
set "data1=!data1:~0,-1!"
) set "data1=!data1:~1,-1!" set "teststring=!teststring!!enter!!data1!"
)
) set "teststring=!teststring:|=$!" :splitend
echo !teststring!| findstr !splitstrempty! >nul && (
set "teststring=!teststring:%splitstrempty%=%splitstr%!"
set /a inforindex+=1
if !inforindex! == !inforsum! (
set inforindex=0
goto splitstart
)
goto splitend
) || (
set inforindex=0
goto splitstart
) :splitstart
set "splitstrempty= $"
echo !teststring!| findstr !splitstrempty! >nul && (
set "teststring=!teststring:%splitstrempty%=%splitstr%!"
set /a inforindex+=1
if !inforindex! == !inforsum! (
set inforindex=0
goto headsplit
)
goto splitstart
) || (
set inforindex=0
goto headsplit
) :headsplit
set "teststring=!teststring:$=,!"
set teststring=!teststring:~1,-1! :stringLOOP
if "!teststring!" EQU "" (
goto END
) :: 注意:切割符号
for /f "delims=;" %%a in ("!teststring!") do (
set substring=%%a
)
if "!substring:~-1!"==" " (
set "substring=!substring:~0,-1!"
)
if "!substring:~-1!"==" " (
set "substring=!substring:~0,-1!"
)
if "!substring:~0,1!"==" " (
set "substring=!substring:~1!"
)
echo !substring!>>%csvfile% :striploop
set stripchar=!teststring:~0,1!
set teststring=!teststring:~1! :: 如果为空字符串,就结束
if "!teststring!" EQU "" (
goto END
) if "!stripchar!" NEQ "!enter!" (
set "substring="
goto striploop
) goto stringloop
) :END pause

bat-MD文件转CSV文件的更多相关文章

  1. SQLite新建数据库及txt文件(CSV文件)导入

    1.安装准备: Windows系统环境: 安装:SQLiteExpert  及 官网的SQLite tool  我们要用到其中的SQLite.exe       地址:https://www.sqli ...

  2. js操作一般文件和csv文件

    js操作一般文件和csv文件 将文本文件读成字符串 <input type="file" id="upload"> document.getElem ...

  3. 将Excel文件转为csv文件的python脚本

    #!/usr/bin/env python __author__ = "lrtao2010" ''' Excel文件转csv文件脚本 需要将该脚本直接放到要转换的Excel文件同级 ...

  4. Python之xlsx文件与csv文件相互转换

    1 xlsx文件转csv文件 import xlrd import csv def xlsx_to_csv(): workbook = xlrd.open_workbook('1.xlsx') tab ...

  5. 【Github】如何下载csv文件/win10如何修改txt文件为csv文件

    csv文件:逗号分隔值(Comma-Separated Values,CSV,有时也称为字符分隔值,因为分隔字符也可以不是逗号) 右键点击raw按钮,选择目标另存为,下载的是txt文件 win10如何 ...

  6. 用opencsv文件读写CSV文件

    首先明白csv文件长啥样儿: 用excel打开就变成表格了,看不到细节 推荐用其它简单粗暴一点儿的编辑器,比如Notepad++, csv文件内容如下: csv文件默认用逗号分隔各列. 有了基础的了解 ...

  7. 【CSV文件】CSV文件内容读取

    CSV(逗号分隔值文件格式) 逗号分隔值(Comma-Separated Values,CSV,有时也称为字符分隔值,因为分隔字符也可以不是逗号),其文件以纯文本形式存储表格数据(数字和文本).纯文本 ...

  8. Weka里如何将arff文件或csv文件批量导入MySQL数据库(六)

    这里不多说,直接上干货! 前提博客是 Weka中数据挖掘与机器学习系列之数据格式ARFF和CSV文件格式之间的转换(四) 1.将arff文件批量导入MySQL数据库 我在这里,arff文件以Weka安 ...

  9. 爬虫文件存储:txt文档,json文件,csv文件

    5.1 文件存储 文件存储形式可以是多种多样的,比如可以保存成 TXT 纯文本形式,也可以保存为 Json 格式.CSV 格式等,本节我们来了解下文本文件的存储方式. 5.1.1 TXT文本存储 将数 ...

  10. php上传excle文件,csv文件解析为二维数组

    解析上传的CSV文件不是什么难事,直接读取转成你想要的数组样子就OK了. public function putStoreStockIn ($filePath = '') { $file = fope ...

随机推荐

  1. 覆盖率检查工具:JaCoCo 食用指南

    一:概述 众所周知,软件的代码覆盖率是衡量软件质量的重要指标, 我们今天简单介绍 JaCoCo 的实际使用示例,它是目前在大多数 Java 项目中应用最广泛的覆盖率检测框架 更多资料参考:JaCoCo ...

  2. 合宙AIR105(三): 定时器, 定时器中断和PWM输出

    目录 合宙AIR105(一): Keil MDK开发环境, DAP-Link 烧录和调试 合宙AIR105(二): 时钟设置和延迟函数 合宙AIR105(三): 定时器, 定时器中断和PWM输出 Ai ...

  3. springboot available: expected at least 1 bean which qualifies as autowire candidate奇葩问题

    Exception encountered during context initialization - cancelling refresh attempt: org.springframewor ...

  4. Node.js精进(3)——流

    在 JavaScript 中,一般只处理字符串层面的数据,但是在 Node.js 中,需要处理网络.文件等二进制数据. 由此,引入了Buffer和Stream的概念,两者都是字节层面的操作. Buff ...

  5. rhel安装vmtools

    第一步,vmware登录虚拟机,菜单栏找到"虚拟机"--"安装TOOLS" //如果打开虚拟机的光驱后没有文件.那么重复以上操作. 第二步,拷贝压缩文件到桌面: ...

  6. docker删除镜像报错 Error response from daemon: conflict: unable to delete f73fe6298efc (cannot be forced) - image has dependent child images

    方法1 docker rmi 镜像ID 方法2 docker rmi -f 镜像ID 方法3 docker rmi 镜像仓库名:tag

  7. throw关键字和Objects非空判断_requireNonNull方法

    作用: 可以使用throw关键字在指定的方法中抛出指定的异常 使用格式: throw new xxxException("异常产生的原因") 注意: 1.throw关键字必须写在方 ...

  8. C#程序设计的6大原则

    设计模式:面向对象语言开发过程中,遇到各种场景和问题,解决方案和思路沉淀下来,就是设计模式.俗称,套路 设计模式的六大原则:理解为面向对象语言开发过程中推荐的一些指导性的原则,通俗的说是套路的 套路 ...

  9. JS常用的3种弹出框

    1.提示框 alert // 没有返回值 alert('你好'); 2.确认框 confirm // 返回 false/true let res = confirm('确定删除?'); if(res ...

  10. linux文件校验

    最近在一次安装centos7程序中遇到了网速很卡的情况,不得已采用了百度云的离线下载功能,后来上传进入虚拟机内,结果遇到无法上传的情况,后来经过转码后才上传成功,详情http://www.cnblog ...