Delete header lines and some other info

Microsoft Microsoft windows xp pro full...
August 31, 2009 at 22:38:13
Specs: Windows XP
Hi,

I have to process multi files, such as *.csv, with the content as follows:


"Result : ABC ABC "
"Date Time: "
"Result : ABCD.. ABC"
"Total of 303003"

"Time","Period","NAME","T1:All information","T2:Some Information"

10:20,60,TEST1,10,20
10:20,60,TEST2,20,30
10:20,60,TEST3,10,40

What I would like to get the output file will be:

"Time","Period","NAME","T1","T2"
10:20,60,TEST1,10,20
10:20,60,TEST2,20,30
10:20,60,TEST3,10,40

Appreciate your help.

Thanks
Alex


See More: Delete header lines and some other info

Report •


#1
September 1, 2009 at 08:29:00
If the initial line to be copied ("Time","Period","NAME","T1","T2") is always the sixth, then this may work:

@echo off
setlocal enabledelayedexpansion
set filter=dir /b /a-d *.csv
for /f "tokens=* delims=" %%a in ('%filter%') do (
set file="%%a"
call :do
)
goto :eof
:do
for /f "usebackq skip=5 delims=" %%1 in (!file!) do (
echo %%1>>new!file!
)
goto :eof


Report •

#2
September 1, 2009 at 19:55:52
Thanks ricardo647 for your input, the first 6 extra headers can be removed. However, I also would like the
initial header of the output file to be truncated as well.

Original:

"Time","Period","NAME","T1:All information","T2:Some Information"

To be changed to:

"Time","Period","NAME","T1","T2"

Thanks.


Report •

#3
September 2, 2009 at 15:37:18
Is the truncated header to be identical in all output files?


Report •

Related Solutions

#4
September 2, 2009 at 21:14:30
If your answer to Wahine's question would be affirmative, then that's the modified bat:

@echo off
setlocal enabledelayedexpansion
set filter=dir /b /a-d *.csv
for /f "tokens=* delims=" %%a in ('%filter%') do (
set file="%%a"
echo "Time","Period","NAME","T1","T2">new!file!
call :do
)
goto :eof
:do
for /f "usebackq skip=6 delims=" %%1 in (!file!) do (
echo %%1>>new!file!
)
goto :eof


Report •


Ask Question