Monday 3 March 2008

batch magic!

problem: client has a generated csv of months credit notes issued, each item credited should be (but sometimes not due to human error) flagged as damaged, quality issue, shortage, not-as-ordered or error (*d*, *q*, *s*, *nao*, *e*). a summary of each catergory should be generated for that month. during the brief i offered a futher category of 'misc' for items not flagged and was hailed as the hero i am (for a short while).

what im not doing: playing football tonight probably... it has snowed!

batch solves the above, toffee!

setlocal enabledelayedexpansion
copy foo.csv cred.csv
set foo=foo
for %%a in (d,q,nao,s,e) do (
type !foo!.csv find /i "*%%a*" >> %%a.csv
type !foo!.csv find /i /v "*%%a*" >> "%%a%%a.csv"
del !foo!.csv
set foo=%%a%%a
)
rename ee.csv misc.csv

notes on the 'cdrill.bat'
name the initial file 'foo.csv'
need setlocal or the variable expands to 'e' instantly
piping output of type for tidyness (no ----- blah.csv at head of file as when 'find' is used), pipe doesnt seem to show up in post

No comments: