0

I'm trying to read a column of numbers from the .txt file and place them in the .csv in the second column.

How to define the second column in batch?

for /f "tokens=1 delims= " %%i in (issn.txt) do (
 >>"anzahl.csv" echo %%i
7
  • 1
    I don't think you can define the second column in batch. I would loop through each line, and re-write it as <existing line> + <second column> Commented Feb 28, 2017 at 17:27
  • I don't have any plans how to do it. Commented Feb 28, 2017 at 17:56
  • 1
    IMHO Insufficient information about the files. BTW "tokens=1 delims= " are default values that can be omitted. The opening parenthesis following do has no closing pendant. To have an empty first column simply echo ,%%i Commented Feb 28, 2017 at 18:00
  • 1
    IMHO still insufficient information about the files. Does the csv file have a header? How do you want to associate the entries? One by one? You should read what a minimal reproducible example is Commented Feb 28, 2017 at 18:11
  • 1
    A few lines showing typical input from the two files and expected result would clarify matters enormously. Commented Feb 28, 2017 at 19:05

1 Answer 1

2

This will create file New-Anzahl.csv which has empty col2's when number of entries in issn.txt is less than anzahl.csv count. Other way around issn.txt overhang is truncated.

@Echo Off & SetLocal EnableDelayedExpansion
Set "FileA=anzahl.csv"
Set "FileB=issn.txt"
<%FileB% (For /f "delims=" %%A in (%FileA%) Do (
    Set "B="&Set /P "B="
    Echo:%%A,!B!
)) >New-%FileA%
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.