Deleting headers of multiple csv files using batch command

July 24, 2019 at 23:04:27
Specs: Windows 10
How can we remove headers of multiple csv files? I am combining them using below command:
copy *.csv newfile.csv

See More: Deleting headers of multiple csv files using batch command

Reply ↓  Report •

#1
July 25, 2019 at 01:58:56
(I have a feeling it is going to be a triple for loop)

Could you give an example of a header?

i5-6600K[delid]@4.9GHz/4.4GHz cache@1.504v | 2x4GB Crucial-DDR4-2400CL17@CL12-15-15-28 1T 3000MHz@1.45v | Sapphire Nitro+ SE RX 590 8GB@1450Mhz core@0.925v/2250MHz@1500MHz timings BiosModded


Reply ↓  Report •

#2
July 25, 2019 at 05:19:40
For the testing purpose I am using below files:
book1.csv (1st input file)

Name Age
Rahul 23
Rajeev 34

book2.csv (2nd input file)

Name Age
Mahesh 23
Lalit 34

newfile.csv (output file I am getting)

Name Age
Rahul 23
Rajeev 34
Name Age
Mahesh 23
Lalit 34

Row no 4 is having header again from the second file. i do not want to have header from all the files. It should come only from the 1st file

message edited by lltmehta81


Reply ↓  Report •

#3
July 25, 2019 at 06:51:05
here ya go(save as whatever.bat & run from the folder/dir where book1 & 2.csv are located):

@echo off
echo Name Age>newfile.csv
for /l %%A in (1,1,2) do for /f "skip=1 tokens=* delims= " %%a in ('type book%%A.csv') do echo %%a>>newfile.csv
echo newfile.csv should have been created in directory: "%~dp0"
pause>nul
exit/b

i5-6600K[delid]@4.9GHz/4.4GHz cache@1.504v | 2x4GB Crucial-DDR4-2400CL17@CL12-15-15-28 1T 3000MHz@1.45v | Sapphire Nitro+ SE RX 590 8GB@1450Mhz core@0.925v/2250MHz@1500MHz timings BiosModded


Reply ↓  Report •

Related Solutions

#4
July 25, 2019 at 23:07:10
Thanks for your help but there is a small modification required. Output is coming like below"
Name Age
Rahul 23
Rajeev 34
Mahesh 23
Lalit 34

Column headers "Name" and "Age" are coming in the first column only. Ideally "Name" should come in the first column header and "Age" should come in the second column header. Please suggest.


Reply ↓  Report •

#5
July 26, 2019 at 03:08:38
yeah thats kinda what i found to be weird, like the fileextension .csv stands for comma seperated values.
so i guess we'll try that ;)

i5-6600K[delid]@4.8GHz@1.456v | 2x4GB Crucial-DDR4-2400CL17@CL12-15-15-28 1T 3000MHz@1.45v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.00v/2235MHz@1500MHz timings BiosModded


Reply ↓  Report •

#6
July 26, 2019 at 03:11:41
this worked for me:

@echo off
echo Name,Age>newfile.csv
for /l %%A in (1,1,2) do for /f "skip=1 tokens=1,2 delims= " %%a in ('type book%%A.csv') do echo %%a,%%b>>newfile.csv
echo newfile.csv should have been created in directory: "%~dp0"
pause>nul
exit/b

i5-6600K[delid]@4.8GHz@1.456v | 2x4GB Crucial-DDR4-2400CL17@CL12-15-15-28 1T 3000MHz@1.45v | Sapphire Nitro+ SE RX 590 8GB@1525Mhz core@1.00v/2235MHz@1500MHz timings BiosModded


Reply ↓  Report •

#7
July 29, 2019 at 01:12:24
Thanks!!
It is working fine now. One final help that our script should not dependent upon the filename (book1.csv,... in this case). It should read whatever csv files are available in the folder. It should also inherit whatever formats are applied on the input files.

Reply ↓  Report •

Ask Question