Solved Merge two CSV using power-shell or Batch script

June 19, 2020 at 06:40:41
Specs: Windows 7
Hi All,

I want to merge two CSV's using Powershell or Batch script.
Both CSV format are as follow.

CSV 1:

Name age roll_no Brach
Soman 21 22 IT
Ritu 22 22 csv
Neeta 21 33 IT

CSV 2 :

Class Collage
BE1 MIT


Expected Output:

Name age roll_no Brach Class Collage
Soman 21 22 IT BE1 MIT
Ritu 22 22 csv BE1 MIT
Neeta 21 33 IT BE1 MIT


How to merge?
Any help?


See More: Merge two CSV using power-shell or Batch script

Reply ↓  Report •

#1
June 19, 2020 at 22:20:41
Looks like a "trick question", with a ton of shoes yet to drop and snares in wait, but I'll give it a dodge:
::-------------- begin batch-script "merjcsv.bat"
@echo off & setlocal
:: only two lines? header and data-field? NAH.
set head=
for /f "tokens=*" %%a in (csv_2) do (
if not defined head (set head=%%a) else (set append=%%a)
)

set hh=
for /f "tokens=*" %%a in (csv_1) do (
if not defined hh (
echo %%a,%head%
set hh=%%a
) else (echo %%a,%append%)
)
:: ------------ end prototype script. NOTE that output is to screen. just redirect if you want
:: to go to file.

message edited by nbrane


Reply ↓  Report •

#2
June 20, 2020 at 12:11:38
✔ Best Answer
I asked this a while ago on spiceworks, have a look at Neally's answer(PowerShell)

https://community.spiceworks.com/to...


Reply ↓  Report •

#3
June 20, 2020 at 12:17:30
you can also have a look at this code i posted

https://community.spiceworks.com/to...


Reply ↓  Report •
Related Solutions


Ask Question