# Solved trouble removing headers from ascii/text file

November 3, 2011 at 19:07:50
Specs: Windows 7
 I need to remove the first 6 lines from over 1800 ascii (text) files e.g.ncols 43nrows 43xllcorner 268828.5yllcorner 6674341.5cellsize 3NODATA_value -9999-9999 -9999 -9999 3 3 3 3 3 3 8 8 8 8 -9999 -9999 3 3 3 8 8 3 3 3 8 etcI can remove the lines using the 'more' command in prompt but have only figured out how to do this one file at a time.I can remove some of the lines (those containing "L") using the following batch @echo offsetLocal EnableDelayedExpansionfor /f "skip=6 tokens=*" %%G in ('dir /b c:\working\text *.txt') do (set pre=%%~nGset fname=%%Gfor /f "tokens=* delims= " %%N in ("!fname!") do (type "%%N" | find /v "l" >> !pre!.new))However, after the third .new file, something goes wrong and my data in the original text file starts replicating itself in the .new file. Can someone please offer this novice some advice (very green - my first crack at creating batch) CheersRenae

See More: trouble removing headers from ascii/text file

#1
November 4, 2011 at 01:48:34
 Something wrong with this path ('dir /b c:\working\text *.txt')Please test this, change the output path to suit your needs:@echo off cls setLocal EnableDelayedExpansion for /f "tokens=*" %%G in ('dir /b c:\working\text\*.txt') do ( set infile=%%~nG for /f "tokens=*" %%H in (%%G) do ( more +6 "%%G" > "Output\path\!infile!.new" ) ) Please come back & tell us if your problem is resolved.