Batch file to Delete 1st values in a CSV file

Hewlett-packard / Sitescope
January 27, 2011 at 22:09:22
Specs: Server 2003, 32 CPU / 512GB RAM
Hi,

I have an automated report that I need to take the dirty CSV file and get rid of the first line "SiteScope Monitor Summary Report," and the return it has in it just to have my column headers "Group,name,class,frequency,dependsOn"

CSV file starts with this:
SiteScope Monitor Summary Report,

Group,name,class,frequency,dependsOn,points,url,host,machine,oid,disabled,schedule,errorFrequency,timeout,verifyError,description,monitorDescription,username,proxy,thresholds,Parameters

I just want this:
Group,name,class,frequency,dependsOn,points,url,host,machine,oid,disabled,schedule,errorFrequency,timeout,verifyError,description,monitorDescription,username,proxy,thresholds,Parameters


See More: Batch file to Delete 1st values in a CSV file

Report •


#1
January 27, 2011 at 23:40:41
:: ==========================================
::
:: marcus.bat Fri 28-01-2011 14:32:11.51
@echo off > newfile & setLocal enableDELAYedeXpansion

> newfile echo.Group,name,class,frequency,dependsOn
for /f "skip=1 tokens=* delims= " %%a in (my.csv) do (
>> newfile echo.%%a
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
January 28, 2011 at 03:48:37
@M2, provided that first line is not a blank line.

@OP, use a good file processing tool if you can. Here's a gawk for windows one liner

C:\test>gawk "NF&&!p{p=1;next}p" file

it works even if you have blanks lines preceding your header.

GNU win32 packages | Gawk


Report •

#3
January 28, 2011 at 10:28:37
Ghostdog, I can't install anything on these servers or else I would. Here is my final batch file, let me know what you guys think

copy E:\SiteScope\htdocs\monSummary.csv E:\mdt\monSummary.csv

::We will take the file and remove the first line that is not the column headers
@echo off > newfile & setLocal enableDELAYedeXpansion

> E:\mdt\newfile echo.Group,name,class,frequency,dependsOn,points,url,host,machine,oid,disabled,schedule,errorFrequency,timeout,verifyError,description,monitorDescription,username,proxy,thresholds,Parameters
for /f "skip=1 tokens=* delims= " %%a in (E:\mdt\monSummary.csv) do (
>> E:\mdt\newfile.csv echo.%%a
)

::Run ping command to just pause the whole script for about 5 seconds and to ensure our destination is up.
@ping -n 1 -w 1000 0.0.0.1 > NUL

::Now we will send the file to remote server
WinSCP.exe /console /script=E:\mdt\mdtsync.bat

::Run ping command to just pause the whole script for about 5 seconds
@ping -n 1 -w 1000 0.0.0.1 > NUL

move /Y E:\mdt\monSummary.csv E:\mdt\archive\monSummary.csv
move /Y E:\mdt\newfile E:\mdt\archive\newfile
move /Y E:\mdt\newfile.csv E:\mdt\archive\newfile.csv


Report •
Related Solutions


Ask Question