bat-MD文件转CSV文件
2024-08-27 14:27:11
注意:每个单元格不能出现字符【|、$、;】
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
最新文章
- ABP学习日记1
- Sql Server FOR XML PATH
- EntityFrameWork 使用时碰到的小问题
- socket编程listen函数限制连接数的解决方案
- 【原】Jqxgrid在Java服务器端分页
- HBase性能调优
- Android --通知栏Notification
- 句柄(handle)
- ssh 私匙登录, 文件rswrst权限
- PHP学习笔记(七)
- webView的一些经验总结
- alv行可编辑时带出描述
- SharePoint RBS 安装(集成Office Web Apps)
- Web Worker Best Practices
- PHP二维数组按照键值排序
- ccf-20171203 Crontab问题
- Flink(一)Flink的入门简介
- BZOJ1068 [SCOI2007]压缩 区间动态规划 字符串
- 004-docker命令-容器生命周期管理、容器操作
- 基于duxshop遍历无限级分销用户的纵向递归