|
Answer» hi,
I'm not sure the subject accurately describes my scenario, but here's what I'm trying to do...
I have two text files...
file 1 - "plants.csv" has a list with a REFERENCE number
tomatoes,831 peppers,266 squash,595 apples,338 basil,831 eggplant,595
...and so on...
file 2, "months.csv" contains the same reference number, with a description as well.
january,637 february,338 march,484 april,831 may,266 june,595 july,926
With a batch file, how can I make this happen...
New file name "PlantWhen.csv"
tomatoes,831,april peppers,266,may squash,595,june apples,338,february basil,831,april eggplant,595,june
The plants and months thing are just an example, what I'm trying to do is a little more complicated, but this is a GOOD representation
thanks in advance... That is normally don in Excel or a similar program. Is there a special reason or using a batch file? Tokens and nested loops. In the outer loop, for each line of plants.csv: split line into two tokens, call them A and B, the DELIMITER being a COMMA. (e.g. A=tomatoes B=831) then read each line of months.csv, again splitting the lines into 2 comma-separated tokens, we'll call them C and D (e.g. C=January D=637). Compare token D to token B and if the same write token A token B Token C as a line to PlantWhen.csv.
Geek-9pm, yeah I'd usually do this in excel or a spreadsheet, but I'm writing a script...the VALUES above don't really mean anything.
Salmon, thanks, I had my if statement in the wrong place, your narrative helped tremendously...here's what worked. one line.
for /F "tokens=1-2 delims=," %%A in (plants.csv) do for /F "tokens=1,2 delims=," %%H in (months.csv) do if %%B == %%I echo %%A,%%B,%%H>>PlantWhen.csv
|