我正在为我的公司做点什么。基本上我需要做的是
关键是让它自动化。意思是,我只想按一个按钮或做一步,它会立即为我做第1步和第2步。
问题是我不知道我应该使用或查看的软件或编码。如果有人可以指导我如何处理这个问题,那会很棒吗?
注意:我对这些事情知之甚少但愿意学习。
====
编辑:
举个更好的例子,
File1.csv
Voltage Ampere Power Error ID
==============================================
6V 3A 6W 18-ABB 000123
8V 2A 7W 0 123991
8V 10A 25W 25-ASB 461233
10V 23A 10W 18-ABB 248811
1V 2A 9W 0 321881
File2.csv
Voltage Ampere Power Error ID
==============================================
6V 4A 6W 0 312313
3V 5A 7W 0 123312
2V 10A 5W 25-ASB 461643
1V 2A 10W 18-ABB 656474
11V 2A 9W 0 124242
我想要实现的目标,
将file1和file 2编译成一个master.csv,如下所示,
master.csv
File1
Voltage Ampere Power Error ID
==============================================
6V 3A 6W 18-ABB 000123
8V 2A 7W 0 123991
8V 10A 25W 25-ASB 461233
10V 23A 10W 18-ABB 248811
1V 2A 9W 0 321881
File2
Voltage Ampere Power Error ID
==============================================
6V 4A 6W 0 312313
3V 5A 7W 0 123312
2V 10A 5W 25-ASB 461643
1V 2A 10W 18-ABB 656474
11V 2A 9W 0 124242
master.csv必须包含编译时的文件名。从master.csv中,找到并隔离机器ID和错误代码18-ABB或25-ASB(它将是可变的,但如果它是0,则表示没有错误)到一个新的被调用的例如outputerror.csv文件中。
标题(电压等)需要转发到新的outputerror.csv文件。
因此,outputerror.csv应如下所示,
outputerror.csv
Voltage Ampere Power Error ID
==============================================
File1
6V 3A 6W 18-ABB 000123
8V 10A 25W 25-ASB 461233
10V 23A 10W 18-ABB 248811
File2
2V 10A 5W 25-ASB 461643
1V 2A 10W 18-ABB 656474
答案 0 :(得分:0)
<强>更新强>
@ECHO OFF
REM Delete any old output files, ignoring any error messages
DEL MASTER.CSV ERROR.CSV 2>NUL:
REM Keep track of file number in FNUM
SET /A FNUM=1
REM Loop through all files whose names look like "2015-03-01.CSV"
FOR %%A IN ( *-*-*.csv ) DO (
SET FNAME=%%A
CALL :PROCESSFILE
SET /A FNUM+=1
)
GOTO :EOF
REM ######################################################################
REM PROCESSFILE SUBROUTINE
REM ######################################################################
:PROCESSFILE
SET /A LNUM=1
REM New file, append its name to MASTER
ECHO %FNAME% >> MASTER.CSV
FOR /F "tokens=*" %%L IN (%FNAME%) DO (
SET LINE=%%L
CALL :PROCESSLINE
SET /A LNUM+=1
)
GOTO :EOF
REM ######################################################################
REM PROCESSLINE SUBROUTINE
REM ######################################################################
:PROCESSLINE
FOR /F "tokens=1-5 delims=," %%T in ("%LINE%") DO (
ECHO %LINE% >> MASTER.CSV
IF %LNUM% EQU 1 (
REM Output header line to ERROR if processing first file
IF %FNUM% EQU 1 ECHO %LINE% >> ERROR.CSV
REM Output filename to ERROR for all files
ECHO %FNAME% >> ERROR.CSV
) ELSE (
REM Output lines where field 4 is not "-" to ERROR
IF NOT "%%W" == "-" ECHO %LINE% >> ERROR.CSV
)
)
GOTO :EOF
答案 1 :(得分:0)
使用awk
实际上更容易 - 事实上它只有2行代码!我建议从here下载awk.exe
。它具有无可比拟的强大功能,可以帮助完成任何脚本或文本处理任务。
手册可用here。
然后整个事情变成了许多注释行和2行代码(第三行和最后一行),它们与我的其他全Windows解决方案一样运行。
@ECHO OFF
REM Print the contents of all CSV files whose names look like a date, e.g. 2012-11-01.csv, and add their name in ahead of line 3
awk "FNR==3{print FILENAME}1" *-*-*.csv > MASTER.CSV
REM From MASTER.CSV, print the following lines out to file ERROR.CSV:
REM ... first 3 lines, i.e. Record Number < 4
REM ... any lines containing "CSV" or "csv"
REM ... no lines with "Voltage" or "="
REM ... any lines with field4 != "0"
awk "NR<4 || /csv/ || /CSV/{print;next} /Voltage|=/{next} $4!=\""0\""" MASTER.CSV > ERROR.CSV