本帖最后由 qixiaobin0715 于 2024-1-12 11:11 编辑
考虑不是太成熟,代码应当还能简化,只是提供一种思路:- @echo off
- setlocal enabledelayedexpansion
- (for /f "tokens=1*" %%a in (a.csv) do (
- setlocal enabledelayedexpansion
- set FirstCol=%%a
- for %%j in (%%b) do (
- for /f "delims=0123456789." %%k in ("#%%j") do (
- if not "%%k"=="#" (
- if !x! equ 3 (
- set /a y+=1
- set _!y!=!str!
- ) else if !x! equ 4 (
- if defined _!y! (
- for /l %%l in (1,1,!y!) do (
- if defined FourthCol (
- echo,%%a !_%%l! !FourthCol!
- ) else (
- echo,%%a !_%%l!
- )
- set _%%l=
- )
- set FourthCol=
- set y=0
- )
- echo,%%a !str!
- )
- set str=%%j
- set x=0
- ) else (
- set str=!str! %%j
- set /a x+=1
- if !x! equ 4 set FourthCol=%%j
- )
- )
- )
- if defined _!y! (
- for /l %%l in (1,1,!y!) do (
- if defined FourthCol (
- echo,!FirstCol! !_%%l! !FourthCol!
- ) else (
- echo,!FirstCol! !_%%l!
- )
- )
- )
- echo,!FirstCol! !str!
- endlocal
- ))>out.csv
- pause
复制代码
|