Solved Split CSV in multiple CSV on column base

May 7, 2020 at 08:03:47
Specs: Windows 7
I want to split CSV file on column basis.

I have following csv which contain 10 column or may be more than that.I want to split csv file into multiple csv after 5th columns with all values by using "Batch script" or "PowerShell script".


Input CSV file:-

Name age gender city empno Deg Experience Mob_no Salary Martial status
Rucha 30 Female pune 123 ME 5 yeasrs 9988776655 50000 Married
Neeta 25 Female pune 132 BE 2 yeasrs 8899667755 30000 Married


Expected output

Output1.csv

Name age gender city empno
Rucha 30 Female pune 123
Neeta 25 Female pune 132

output2.csv

Deg Experience Mob_no Salary Martial status
ME 5 yeasrs 9988776655 50000 Married
BE 2 yeasrs 8899667755 30000 Married


Any Help????


See More: Split CSV in multiple CSV on column base

Reply ↓  Report •

#1
May 7, 2020 at 08:52:30
Try this in PowerShell:

Get-Content -Path "folder\file.csv" | Select-Object Name, Age, Gender, City, Empno | Out-File "folder\Output1.csv"

Then just change the columns for ouput2.csv

Dont know if this works, havent tested it as im not home atm. Let me know how it goes.


Reply ↓  Report •

#2
May 7, 2020 at 11:56:07
Thanks for your suggestion.

This solution creates only two objects with just column names in respective CSVs.

Output1.csv -
Name :
age :
emp_no :
des :
salary :
experience :

Name :
age :
emp_no :
des :
salary :
experience :

Name :
age :
emp_no :
des :
salary :
experience :


Output2.csv -

city :
maritial_status :
gender :
DOB :
Mob_no :
Degree :

city :
maritial_status :
gender :
DOB :
Mob_no :
Degree :

city :
maritial_status :
gender :
DOB :
Mob_no :
Degree :

I expect the output in table format.

Output1.csv

Name age gender city empno
Rucha 30 Female pune 123
Neeta 25 Female pune 132


Reply ↓  Report •

#3
May 7, 2020 at 11:58:44
✔ Best Answer
Forget that first comment..

Import-CSV -Path "folder\file.csv" | Select-Object Name, Age, Gender, City, Empno | Export-CSV -Path "folder\file.csv"

Just tested it: https://imgur.com/a/n0mME0X


Reply ↓  Report •

Related Solutions

#4
May 7, 2020 at 12:02:11
Use this:

Import-CSV -Path "path" | Format-Table

https://imgur.com/a/DcHa3mB


Reply ↓  Report •

#5
May 7, 2020 at 13:05:38
If your delimiter is a comma, so just give a try like that :

@echo off
Set "InputCSV=Test.csv"
> "%~dp0Output1.csv" (@for /f "tokens=1-5 delims=," %%a in ('Type "%InputCSV%"') do echo %%a;%%b;%%c;%%d;%%e)
> "%~dp0Output2.csv" (@for /f "tokens=6-11 delims=," %%a in ('Type "%InputCSV%"') do echo %%a;%%b;%%c;%%d;%%e;%%f)
If Exist "%~dp0Output1.csv" Start "" "%~dp0Output1.csv"
If Exist "%~dp0Output2.csv" Start "" "%~dp0Output2.csv"
Exit


Reply ↓  Report •

#6
May 7, 2020 at 14:53:05
Thank you for solution.

Its working as per my expectation.

Thanks a lot.


Reply ↓  Report •

Ask Question