本文介绍了使用cmd提示将.txt文件连接为一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有367个.txt文件,需要通过Windows cmd提示符将其连接成一个大的.txt文件。每个文件上都有名称和日期,例如

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,
和x.20150402.000000.txt,
... ,
和x.20160401.000000.txt

andx.20150401.000000.txt,andx.20150402.000000.txt,...,andx.20160401.000000.txt

在每个文件中,我有7列时间(以julians为单位)和6个其他可测量变量。我需要所有367的连续文件,我想通过cmd提示符进行操作。

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.

推荐答案

我想您可以这样做如果目录中没有可能与该模式匹配的旧文件,则作为一条命令。

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

或者,可以将其内置到.bat脚本中,以生成您上一个问题中的.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%

这篇关于使用cmd提示将.txt文件连接为一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 21:30