We help IT Professionals succeed at work.
Get Started

Remove Columns from CSV file, save results to new file

markpalinux
markpalinux asked
on
4,279 Views
Last Modified: 2012-05-09
Looking for help creating a script that takes input parameters...
I want to take a file l like file1 - give a script name, input filename, output filename , and a string of column names to keep...

script.ps1 file1.csv file2.csv name,address

File1.csv ( see below )
name,fullname,phone,address

script would remove all columns that are not in the columns input, result would show:

Output
File2.csv
name,address

I had a vbscript that would do this a while back but I lost it.  That script also created the file file in excel, which would be fine for this as well.

Thank you.
Mark

File1.csv
name,fullname,phone,address
wsmith,"William Smith",111-111-1111,111 street
bcar,"Billy Car",222-222-2222,2222 road
dward,"David Ward",333-333-3333,3333 circle


File2.csv
name,address
wsmith,111 street
bcar,2222 road
dward,3333 circle

Open in new window

Comment
Watch Question
PowerShell Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE