0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

bat2

Posted at

@echo off
rem ①ヘッダー行含めて一行ずつ新しいcsvファイルに書き出す。
set csv_file=test.csv

rem CSVファイルの存在有無を確認
if not exist %csv_file% (
echo CSVファイルが存在しないため、処理を終了します。
pause
exit
)

rem ①ヘッダー行含めて一行ずつ新しいcsvファイルに書き出す。
rem ヘッダー行を取得してheader.csvに代入
for /f "delims=" %%i in (%csv_file%) do (
set header=%%i
echo %%i > header.csv
goto :jump
)
:jump
echo %header%

rem 2行目以降をCSV出力する
setlocal enabledelayedexpansion
set /a cnt=1
for /f "skip=1 delims=" %%i in (!csv_file!) do (
echo !header! > ./output/!cnt!.csv
echo %%i >> ./output/!cnt!.csv
set /a cnt+=1
)

rem ②書き出したcsvファイル名を各ファイルの中身に応じて書き換える。
for %%f in (./output/*.csv) do (
setlocal enabledelayedexpansion
for /F "skip=1 delims=, tokens=1,3" %%a in (./output/%%f) do (
set file_name=%%a_%%b
call :Trim !file_name!
move output%%f output!file_name!.csv
)
endlocal
)
exit

:Trim
set file_name=%*

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?