- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv_compare_script.cmd
More file actions
Latest commit
97 lines (93 loc) · 3.73 KB
/
Copy pathcsv_compare_script.cmd
File metadata and controls
97 lines (93 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
@echooff
SetlocalEnableDelayedExpansion
for /f "delims="%%ain ('wmic OS Get localdatetime ^| find"."') dosetDateTime=%%a
settstamp=%DateTime:~0,4%%DateTime:~4,2%%DateTime:~6,2%%DateTime:~8,2%%DateTime:~10,2%%DateTime:~12,2%
set"edit_doc=edit_data"
set"_proc_edit=_edit_process"
set"_proc_new=_new_process"
set"_merge_uid=_merge_uid"
set"new_doc=new"
set"_new_uid=_new_uid"
set"_merge=updated"
set"comp_doc=complete%tstamp%"
REM procedures for reformatting original data to prevent parsing errors.
ifexist%new_doc%.csv ( ifexist%edit_doc%.csv (
typenul>%_proc_edit%.csv &&attrib +h %_proc_edit%.csv
typenul>%_proc_new%.csv &&attrib +h %_proc_new%.csv
call :reformat%edit_doc%.csv , %_proc_edit%.csv
call :reformat%new_doc%.csv , %_proc_new%.csv
)) else (( echo File Error: either %edit_doc%.csv or %new_doc%.csv was not found. ) &&pause&exit /b 1 )
REM procedures for pairing persistent data tuples with the newest dataset,
REM and merging matches into a newly generated dataset.
ifexist%_proc_edit%.csv ( ifexist%_proc_new%.csv (
typenul>%_merge%.csv &&attrib +h %_merge%.csv
for /f "tokens=1-7 delims=,"%%ain (%_proc_new%.csv) do (
for /f "tokens=1-7 delims=,"%%hin (%_proc_edit%.csv) do (
if%%bequ%%i ( echo%%a,%%b,%%c,%%d,%%e,%%f,%%n>>%_merge%.csv )))
)) else (
( echo Processing Error 1.1: temporary data file structures not found )
call :clean_up
pause&exit /b 1
)
REM procedures for subroutine calls to extract unique identifiers from newest dataset
REM and newly generated dataset.
ifexist%_merge%.csv (
typenul>%_merge_uid%.csv &&attrib +h %_merge_uid%.csv
typenul>%_new_uid%.csv &&attrib +h %_new_uid%.csv
call :extract%_merge%.csv , %_merge_uid%.csv , "tokens=2 delims=,"
call :extract%new_doc%.csv , %_new_uid%.csv , "skip=1 tokens=2 delims=,"
) else (
( echo Processing Error 1.2: temporary data file structures not found )
call :clean_up
pause&exit /b 1
)
REM procedures for comparing differences between the extracted lists of unique identifiers,
REM missing items (not found in edited dataset) will be copied over from the newest dataset.
ifexist%_new_uid%.csv ( ifexist%_merge_uid%.csv (
for /f %%ain ('type %_new_uid%.csv ^| find /i "cod" /c') dosetline_cnt=%%a
for /f %%ain ('fc /lb %line_cnt%%_new_uid%.csv %_merge_uid%.csv ^| find /i "cod"') do (
for /f "tokens=1-7 delims=,"%%bin (%_proc_new%.csv) do (
if%%aequ%%c ( echo%%b,%%c,%%d,%%e,%%f,%%g,%%h>>%_merge%.csv )))
)) else (
( echo Processing Error 1.3: temporary data file structures not found )
call :clean_up
pause&exit /b 1
)
typenul>%comp_doc%.csv && ( echo ,uid,date,datetime,text,num, >%comp_doc%.csv )
type%_merge%.csv >>%comp_doc%.csv
call :clean_up
endlocal
pause
exit
:reformat
for /f "skip=1 delims="%%# in (%1) do (
REM error handle - for comma delimiter sequences
REM and empty values in tuple - with replacement
settpl=%%#
settpl=!tpl:,,=, ,!
settpl=!tpl:,,=, ,!
for /f "tokens=1-7 delims=,"%%bin (^"!tpl!^") do (
REM exhibit parsed token selectivity
echo%%b,%%c,%%d,%%e,%%f,%%g,%%h>>%2
) || (
echo Error Reading File Found &Exit /b 1
)
)
exit /b
:extract
for /f %3%%ain (%1) do (
REM token selectivity for unique id column
REM at position 1 - after reformat subroutine
echo%%a>>%2
) || (
echo Error Reading File Found &Exit /b 1
)
exit /b
:clean_up
ifexist%_proc_edit%.csv ( del /A:H %_proc_edit%.csv )
ifexist%_proc_new%.csv ( del /A:H %_proc_new%.csv )
ifexist%_merge_uid%.csv ( del /A:H %_merge_uid%.csv )
ifexist%_new_uid%.csv ( del /A:H %_new_uid%.csv )
ifexist%_merge%.csv ( del /A:H %_merge%.csv )
exit /b
goto :eof