我有一个包含以下内容的csv文件。
userid,userRole,ContentType
1,text1,value1,
2,text2,value2,
我想写一个批处理文件,在csv文件的开头添加几个列标题。我有这段代码只能添加一个额外的列。是否可以根据列位置添加多个列?
e.g。我想在第2和第5位添加一个新列。
@echo off > newfile.csv & setLocal enableDELAYedeXpansion
for /f "tokens=* delims= " %%a in (input.csv) do (
>> newfile.csv echo.FirstName,%%a
)
任何帮助都会得到满足。
答案 0 :(得分:1)
%%e
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>${maven.cucumber.reporting.version}</version>
<executions>
<execution>
<id>execution</id>
<phase>test</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>cucumber-jvm-example</projectName>
<outputDirectory>${project.build.directory}/cucumber-html-reports</outputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
<parallelTesting>false</parallelTesting>
</configuration>
</execution>
</executions>
</plugin>
是&#34;令牌*&#34;,这意味着&#34;线路的其余部分&#34;
您确定,您想在每一行的第2列和第5列上使用相同的字符串吗?
答案 1 :(得分:1)
尽管我在提供的评论中有提示,但没有空列:
@Echo off&Setlocal EnableExtensions EnableDelayedExpansion
Set Row=0
( for /f "tokens=1-5 delims=," %%A in (input.csv) do (
Set /A Row+=1
If !Row! lss 2 (Rem new header
echo %%A,NewSecond,%%B,%%C,%%D,NewFifth,%%E
) Else (Rem insert new empty columns
echo %%A,"",%%B,%%C,%%D,"",%%E
)
)
) >newfile.csv
示例输出:
> type *.csv
input.csv
userid,userRole,ContentType,Col4,Col5
1,text1,value1,"",""
2,text2,value2,"",""
newfile.csv
userid,NewSecond,userRole,ContentType,Col4,NewFifth,Col5
1,"",text1,value1,"","",""
2,"",text2,value2,"","",""