修改14楼的代码,以便解决15楼的问题:- @echo off
- setlocal enabledelayedexpansion
- (for /f "tokens=1*" %%a in (a.csv) do (
- setlocal enabledelayedexpansion
- set Line="%%b"
- set Line=!Line: =" "!
- set Line=!Line:""=!
- for %%j in (!line!,x) 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
- )
- )
- )
- endlocal
- ))>out.csv
- pause
复制代码 这种问题对于锻炼逻辑思维很有好处。顺便练习一下if及set命令的用法。 |