将每个定界符的值拆分为单独的行-批处理 [英] Split values into separate lines for each delimiter - batch

查看:46
本文介绍了将每个定界符的值拆分为单独的行-批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用delimiter =将csv文件的值分割为单独的行,以此作为分割点.即

I'm trying to split the values of a csv file into separate lines using the delimiter=, as a point to split from. i.e.

#csv file 
video1,video2,video3
video4,video5,video6

#Preferred output:
video1,
video2,
video3,
ect....

到目前为止,我有:

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims=, " %%a in (input.csv) do (
set /a N+=1
echo ^%%a^,>>output.csv
)

但是我遇到了参数%% a刚被添加为字符串的问题.我该如何对每个字符串进行分割,然后将字符串放在换行符上?

However I run into the issue of parameter %%a just being added as a string. How would I cause a split instead for each , and put the string onto a newline?

推荐答案

@echo off
setLocal 
for /f "delims=" %%a in (input.csv) do (
 for %%i in (%%a) do echo %%i,>>output.csv
)

每行依次放入 %% a .

使用默认列表定界符(空格,逗号,分号), %% i 用于依次将每个令牌从 %% a 中的行分配给%% i

Using the default list delimiters (space, comma, semicolon) the %%i for assigns each token in turn from the line in %%a to %%i

这篇关于将每个定界符的值拆分为单独的行-批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆