batch file removing specific lines

April 7, 2009 at 07:02:52
Specs: Windows XP
Hello everyone,

I'm hoping someone can help me out. I've got several hundred files that have certain lines that need to be removed. These are CSV files that have multiple headers. One at the beginning, that I want to keep, but if the file is left in this folder for several days, new data is appended to the file inserting new headers as well. I'm looking to write a batch file that will remove all additional lines after the initial header in all the files in the folder, and possibly move it to a different folder once processed.

Is this possible? Please help me out if you can!

Let me know if you need more input.


See More: batch file removing specific lines

Report •


#1
April 7, 2009 at 09:18:02
show samples of your csv files. show what you want in the end.

Unix Win32 tools | Gawk for Windows


Report •

#2
April 7, 2009 at 13:21:55
here's an example of the file:

"RECORDER ID" " DATE" " HOUR" " IN" " UN" "     KW" "   KVAR" "       " "       "   
"51615B        " 040209 0005 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0010 05 "   WT"     345600     201600          0          0 
"51615B        " 040209 0015 05 "   WT"     331200     216000          0          0 
"51615B        " 040209 0020 05 "   WT"     331200     187200          0          0 
"51615B        " 040209 0025 05 "   WT"     331200     216000          0          0 
"51615B        " 040209 0030 05 "   WT"     345600     201600          0          0 
"51615B        " 040209 0035 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0040 05 "   WT"     316800     201600          0          0 
"51615B        " 040209 0045 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0050 05 "   WT"     345600     201600          0          0 
"51615B        " 040209 0055 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0100 05 "   WT"     316800     201600          0          0 
"51615B        " 040209 0105 05 "   WT"     345600     216000          0          0 
"51615B        " 040209 0110 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0115 05 "   WT"     316800     201600          0          0 
"51615B        " 040209 0120 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0125 05 "   WT"     345600     216000          0          0 
"51615B        " 040209 0130 05 "   WT"     331200     187200          0          0 
"51615B        " 040209 0135 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0140 05 "   WT"     331200     216000          0          0 
"51615B        " 040209 0145 05 "   WT"     345600     201600          0          0 
"51615B        " 040209 0150 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0155 05 "   WT"     331200     216000          0          0 
"51615B        " 040209 0200 05 "   WT"     345600     201600          0          0 
"51615B        " 040209 0205 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0210 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0215 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0220 05 "   WT"     316800     201600          0          0 
"51615B        " 040209 0225 05 "   WT"     345600     201600          0          0 
"51615B        " 040209 0230 05 "   WT"     331200     216000          0          0 
"51615B        " 040209 0235 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0240 05 "   WT"     316800     201600          0          0 
"51615B        " 040209 0245 05 "   WT"     345600     201600          0          0 
"51615B        " 040209 0250 05 "   WT"     316800     201600          0          0 
"51615B        " 040209 0255 05 "   WT"     331200     187200          0          0 
"51615B        " 040209 0300 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0305 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0310 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0315 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0320 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0325 05 "   WT"     345600     201600          0          0 
"51615B        " 040209 0330 05 "   WT"     331200     187200          0          0 
"51615B        " 040209 0335 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0340 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0345 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0350 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0355 05 "   WT"     331200     187200          0          0 
"51615B        " 040209 0400 05 "   WT"     331200     201600          0          0 
"51615B        " 040209 0405 05 "   WT"     331200     201600          0          0 
"RECORDER ID" " DATE" " HOUR" " IN" " UN" "     KW" "   KVAR" "       " "       "   
"51615B        " 040309 0005 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0010 05 "   WT"     316800     201600          0          0 
"51615B        " 040309 0015 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0020 05 "   WT"     331200     216000          0          0 
"51615B        " 040309 0025 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0030 05 "   WT"     316800     216000          0          0 
"51615B        " 040309 0035 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0040 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0045 05 "   WT"     316800     216000          0          0 
"51615B        " 040309 0050 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0055 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0100 05 "   WT"     316800     201600          0          0 
"51615B        " 040309 0105 05 "   WT"     331200     216000          0          0 
"51615B        " 040309 0110 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0115 05 "   WT"     316800     201600          0          0 
"51615B        " 040309 0120 05 "   WT"     331200     216000          0          0 
"51615B        " 040309 0125 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0130 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0135 05 "   WT"     331200     216000          0          0 
"51615B        " 040309 0140 05 "   WT"     316800     201600          0          0 
"51615B        " 040309 0145 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0150 05 "   WT"     331200     216000          0          0 
"51615B        " 040309 0155 05 "   WT"     316800     201600          0          0 
"51615B        " 040309 0200 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0205 05 "   WT"     331200     216000          0          0 
"51615B        " 040309 0210 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0215 05 "   WT"     316800     216000          0          0 
"51615B        " 040309 0220 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0225 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0230 05 "   WT"     331200     216000          0          0 
"51615B        " 040309 0235 05 "   WT"     316800     201600          0          0 
"51615B        " 040309 0240 05 "   WT"     331200     216000          0          0 
"51615B        " 040309 0245 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0250 05 "   WT"     316800     201600          0          0 
"51615B        " 040309 0255 05 "   WT"     331200     216000          0          0 
"51615B        " 040309 0300 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0305 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0310 05 "   WT"     316800     216000          0          0 
"51615B        " 040309 0315 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0320 05 "   WT"     331200     216000          0          0 
"51615B        " 040309 0325 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0330 05 "   WT"     316800     201600          0          0 
"51615B        " 040309 0335 05 "   WT"     331200     201600          0          0 
"51615B        " 040309 0340 05 "   WT"     331200     216000          0          0 

What I would like to do is remove all the

"RECORDER ID" " DATE" " HOUR" " IN" " UN" "     KW" "   KVAR" "       " "       "  

headers except for the first. the number of rows between these "headers" varies as well.


Report •

#3
April 7, 2009 at 17:59:49
if you can download Gawk for windows (see my sig) here's an alternative. on the command line,
c:\test> gawk "NR>1 && /RECORD/{next}1" file.txt

Unix Win32 tools | Gawk for Windows


Report •

Related Solutions


Ask Question