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 43
nrows 43
xllcorner 268828.5
yllcorner 6674341.5
cellsize 3
NODATA_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 etc
I 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 off
setLocal EnableDelayedExpansion


for /f "skip=6 tokens=*" %%G in ('dir /b c:\working\text *.txt') do (
set pre=%%~nG
set fname=%%G
for /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)
Cheers
Renae


See More: trouble removing headers from ascii/text file

Report •


#1
November 4, 2011 at 01:48:34
✔ Best Answer
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.


Report •

#2
November 6, 2011 at 16:13:40
Wahine,

This worked like a charm.

Your reply is very much appreciated.

Thank you kindly.
R6.


Report •

Related Solutions


Ask Question