简体   繁体   中英

How to pass variable content from csv file to another file using batch file

For example I have a .csv file name "sample.csv" that reads every row.Now I want to pass the contents of the sample.csv to another file "pass.txt"

(
FOR /F "tokens=1-18* delims=," %%A IN ('type C:\Users\sample.csv') DO (
  set A = %%A
  set B = %%B


  echo %%~A
  echo %%~B

 )
)>youroutputfilename
pause

I can generate another text file using the above code. However what if I want to pass the content of "A" and "B" to another file?

Sample content of pass.txt before script is run:

Put A content Here: 
Put B content Here:

How to do this using batch file?

Sample output after run should be:

Put A content Here: **Apple** 
Put B content Here: **Banana** 

please run this modified code and post it's output:

@echo off
set file=c:\users\sample.csv
if not exist %file% echo input file not found
(
 FOR /F "tokens=1,2 delims=," %%A IN (%file%) DO (
  echo Put A content Here: %%~A
  echo Put B content Here: %%~B
 )
)>pass.txt
type pass.txt
pause

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM