-5

I got a task that says skip the header part of a csv file and copy the rest to another file. I am unable to figure out any way that can do this. I require to do this using command prompt or by writing a batch file code. I tried using for loop but dint worked

  • 3
    Please share your efforts! This is a site for programmers asking specific questions, but not a free code/script request service; so as long as you do not show your code and describe exactly what you have trouble with, this question is too broad and therefore off-topic here. Please read the [tour] and these help articles: [ask], [mcve]. Thank you! – aschipfl Feb 25 '19 at 11:52
  • Try `for /F "skip=1 delims=" %A IN (file.csv) do (@echo %A)>>file1.csv`. Replace `file.csv` and `file1.csv` with your names – double-beep Feb 25 '19 at 11:52
  • If the `.csv` file is not tab delimited, _(or contains necessary tabs)_, then the simplest method would be to use the `More` command, `More +1 "SourceDirectory\Input.csv">"DestinationDirectory\Output.csv"`. Open a Command Prompt window and enter `More /?` to read its usage information. – Compo Feb 25 '19 at 11:58

1 Answers1

1

Except the way Compo suggested (using more with +1 which will exclude the first line), you can use a for /F loop:

@echo off

for /F "skip=1 delims=" %%A IN (file.csv) do (echo %%A)>>file1.csv

which, with the option skip=1 will skip the first line.

Another way would be to loop through the output of more command:

@echo off

for /F "skip=1 delims=" %%A IN ('more "file.csv"') do (echo %%A)>>file1.csv

See the help pages of the following commands in cmd to learn more:

  • for /?
  • echo /?
  • more /?
double-beep
  • 5,031
  • 17
  • 33
  • 41