问题
I have 367 .txt files that I need to concatenate into one big .txt file through the windows cmd prompt. Each file has the name and date on it, e.g.,
andx.20150401.000000.txt, andx.20150402.000000.txt, ..., andx.20160401.000000.txt
Inside each file I have 7 columns for time (in julians) and 6 other measurable variables. I need a continuous file for all 367 and I wanted to do this through the cmd prompt.
回答1:
I suppose you could do this as one command if the directory is clear of old files that might match the pattern.
TYPE andx.*.txt 2>NUL >>sum_file.txt
Alternatively, this could be built into a .bat script that produces the .txt files in your previous question. I doubt that you would want to type all this on the command line. Please note, this is not tested.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET "SUM_FILE=xxxxx.txt"
IF EXIST "%SUM_FILE%" (DEL "%SUM_FILE%")
FOR %%i IN (*.cdf) DO (
andx "%%~i" -o TXT atmos_pressure temp_mean ^
rh_mean wspd_vec_mean wdir_vec_mean ^
org_precip_rate_mean
SET EXITCODE=!ERRORLEVEL!
IF !EXITCODE! NEQ 0 (
ECHO ERORR: andx failed processing "%%~i"
ECHO ERORR: exitcode is !EXITCODE!
GOTO TheEnd
) ELSE (
FOR /F "usebackq skip=1 tokens=*" %%s IN (`TYPE "%%~ni.txt"`) DO (
ECHO>>"%SUM_FILE%" %%s
)
)
)
:TheEnd
EXIT /B %EXITCODE%
来源:https://stackoverflow.com/questions/36695472/concatenate-txt-files-into-one-file-using-cmd-prompt