batch: append two files of CSV into one

May 11, 2011 at 08:58:57
Specs: Windows XP, Intel core 2 DUO/ 2GB
Hallo Mates,

I have 2 csv files with information.
1st: contains file names and versions.
ex: COM; 1.1
CAD; 2.1
SAD; 3.1
2nd: contains file names and versions.
ex: COM; 1.2
CAD; 2.2
MOD; 4.1

Note: Both 1st & 2nd contain some same file names and some file names are only in 1st or in 2nd.

so every file name contain one revision. it may be in both 1st & 2nd or only in 1st or in 2nd.

So folks,

I need a program where I can append both the files and get the output like:

COM 1.1 1.2
CAD 2.1 2.2
SAD 3.1
MOD 4.1

I hope you ppl understood what i need.

Thank you.




See More: batch: append two files of CSV into one

Report •


#1
May 11, 2011 at 16:15:53
Merge both files and sort.
Read and write name then write version Read next and wrte version if different or until name changes. Repeat till EOF.

Report •

#2
May 12, 2011 at 00:22:37
Hallo Fred,

Greetings,

thnx for the info.

Just need a small favour.

If time permits can you please write the code coz I am just the begginer to Batch.

I have two files by name A1.csv & B1.csv.

I need the output by name C1.csv

Thanking you in anticipation.


Report •

#3
May 15, 2011 at 08:09:39
wizard-fred, while you're at it, I need you to do my job ..... by Friday! Not sure what I'm doing, I just started and really need you to finish this assignment for me. I keep the praise.

LOL


"We, the willing, doing the impossible, for the ungrateful"


Report •

Related Solutions

#4
May 16, 2011 at 01:18:18
I have wrote a Prog to Merge both the files but aint working...
Plz check out.
____________________________________

cls

@echo off & setlocal enabledelayedexpansion

set n=1

for /f %%a in (A1.csv) do (
echo %%a
for /f %%c in (B1.csv) do if not defined quit (
echo %%a;%%c>>merged_file.csv
set quit=now
)
set quit=
goto exitloop
)

:exitloop

for /f "skip=1" %%a in (A1.csv) do (
echo %%a

for /f "skip=%n%" %%c in (B1.csv) do if not defined quit (
echo %%a;%%c>>merged_file.csv
set quit=now
)
set quit=
set n=n+1
)

pause
----------------------------------------
My out put is:

file name Version-1 version 2
COM/T.c 1.2 1.2.1
COM/x.h 1.8 1.8.5
COM/b.he 1.6 1.8.5
COm/n.c 1.4 1.8.5
-------------------------------------------------------------
In the second version the O/P is repeating but it shouldnt.

I have tryed many things but aint got solved.

I dont know why the Version-2 is repeating after 2nd line.

In the Prog it should increment and skip the lines when 'n' is incremented.

but i see that n is incrementing but its not skipping and updating for the 2nd file B1.csv.

Please help me out with the solution.


Report •

#5
May 17, 2011 at 01:45:02
Hallo Fred & mates,

Greetings,

I wrote a new Prog which can just merge two files.

But i need to compare and them and write.

Please check it:

cls

@echo off > newfile.csv & setLocal enableDELAYedeXpansion

set N=
for /f "tokens=1-2* delims=," %%a in (A1.txt) do (
set /a N+=1
set M!N!=%%a
)

set N=
for /f "tokens=1-2* delims=," %%b in (B1.txt) do (
set /a N+=1
set I!N!=%%b
)


for /L %%i in (1, 1, !N!) do (
>> newfile.csv echo.!I%%i!;!M%%i!
)
)

Pause
-------------------------------------------------------------------------
My 1st i/ps in A1.txt are like:
COM; 1.1
CAD; 2.1
SAD; 3.1

2nd i/ps in B1.txt are like:
COM; 1.2
CAD; 2.2
MOD; 4.1

I got the output as in CSv with 4 columns.
COM; 1.1 COM; 1.2
CAD; 2.1 CAD; 2.2
SAD; 3.1 MOD; 4.1
.................
But i need the put in 3 coulmns i.e, to compare the files and then write,
& not to repeat the file names.
Ex::
COM 1.1 1.2
CAD 2.1 2.2
SAD 3.1 --
MOD -- 4.1
-----------------------------------------

Please help me.
it can save my Job.

Thnx in advance.



Report •


Ask Question