spargor
spargor

Reputation: 11

Delete first two lines from txt files

I need to delete the first two lines from a very large amount of txt files (about 10.000). I'm looking for a way to do this from the command line or through another semi-automatic procedure. Every file is different from the other, but they all contain some information on the first two lines that I need to get rid of.

Upvotes: 0

Views: 1259

Answers (2)

npocmaka
npocmaka

Reputation: 57252

for %%a in (*.txt) do (
  more +2 <  "%%~fa" > 2linesskipped.txt
  move /y 2linesskipped.txt "%%~fa"
)

without external tools.

Upvotes: 2

theglossy1
theglossy1

Reputation: 553

I think aguslr's answer looks good on a UNIX-derivative system, but I'm guessing since the tags are "cmd" and "batch-file" that you are on Windows. You can get sed for Windows in several places, for example in the UnxUtils ports or more up-to-date ones via Cygwin or GnuWin32. But find is a built-in Windows program that is nothing like the find on UNIX-derivative systems. So you would probably want to replace the second half of the answer with a "for" command in Windows like:

for /r %a in (*.txt) do sed -i '1,2d' %a

Note that if you run this from a batch file you will want to use %%a instead of %a.

Upvotes: 0

Related Questions