deleting multiple column headers in csv file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
bluefire_xl
Posts: 5
Joined: 28 Jan 2016 09:06

deleting multiple column headers in csv file

#1 Post by bluefire_xl » 28 Jan 2016 09:55

I have a csv extract that have repeated header columns on it. The header shows up on every group data. Is there a way to just delete all other instance of that header and just retain the one on the top.

When I try to use findstr it will delete all of my columns.

Matt Williamson
Posts: 82
Joined: 30 Dec 2013 10:16
Location: United States by the big waterfall

Re: deleting multiple column headers in csv file

#2 Post by Matt Williamson » 28 Jan 2016 10:51

Post your code.

bluefire_xl
Posts: 5
Joined: 28 Jan 2016 09:06

Re: deleting multiple column headers in csv file

#3 Post by bluefire_xl » 28 Jan 2016 11:01

This is the code that I used:

Code: Select all

findstr /v /c:"Student Group" %p%Student.csv > %p%Student_%t%.csv


This is my header format Student Group, Group Name. These headers repeat itself on every Student Group on the csv file. When I try to used the code above. It will delete all the header line entry. What I am trying to do is retain the first header line and all duplicate occurrence will be deleted.
Last edited by Squashman on 28 Jan 2016 11:52, edited 1 time in total.
Reason: MOD EDIT: Please use code tags

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: deleting multiple column headers in csv file

#4 Post by Squashman » 28 Jan 2016 11:57

If your header line is shorter than 1024 bytes and does not have any special characters in it, you can use this.

Code: Select all

set /p header=<%p%Student.csv
echo %header% > %p%Student_%t%.csv
findstr /v /c:"Student Group" %p%Student.csv >> %p%Student_%t%.csv

bluefire_xl
Posts: 5
Joined: 28 Jan 2016 09:06

Re: deleting multiple column headers in csv file

#5 Post by bluefire_xl » 29 Jan 2016 12:24

Squashman wrote:If your header line is shorter than 1024 bytes and does not have any special characters in it, you can use this.

Code: Select all

set /p header=<%p%Student.csv
echo %header% > %p%Student_%t%.csv
findstr /v /c:"Student Group" %p%Student.csv >> %p%Student_%t%.csv


This code works! Thank you so much!

Post Reply