Windows batch - concatenate multiple text files into one

前端 未结 9 560
醉梦人生
醉梦人生 2021-01-31 13:53

I need to create a script, which concatenates multiple text files into one. I know it\'s simple to use

type *.txt > merged.txt

But the require

相关标签:
9条回答
  • 2021-01-31 14:34

    We can use normal CAT command to merge files..

    D:> cat *.csv > outputs.csv

    0 讨论(0)
  • 2021-01-31 14:39

    cat "input files" > "output files"

    This works in PowerShell, which is the Windows preferred shell in current Windows versions, therefore it works. It is also the only version of the answers above to work with large files, where 'type' or 'copy' fails.

    0 讨论(0)
  • 2021-01-31 14:39

    You can do it using type:

    type"C:\<Directory containing files>\*.txt"> merged.txt
    

    all the files in the directory will be appendeded to the file merged.txt.

    0 讨论(0)
  • 2021-01-31 14:43

    Windows type command works similarly to UNIX cat.

    Example 1: Merge with file names (This will merge file1.csv & file2.csv to create concat.csv)

    type file1.csv file2.csv > concat.csv
    

    Example 2: Merge files with pattern (This will merge all files with csv extension and create concat.csv)

    When using asterisk(*) to concatenate all files. Please DON'T use same extension for target file(Eg. .csv). There should be some difference in pattern else target file will also be considered in concatenation

    type  *.csv > concat_csv.txt
    
    0 讨论(0)
  • 2021-01-31 14:46

    Place all files need to copied in a separate folder, for ease place them in c drive.

    Open Command Prompt - windows>type cmd>select command prompt.

    You can see the default directory pointing - Ex : C:[Folder_Name]>. Change the directory to point to the folder which you have placed files to be copied, using ' cd [Folder_Name] ' command.

    After pointing to directory - type 'dir' which shows all the files present in folder, just to make sure everything at place.

    Now type : 'copy *.txt [newfile_name].txt' and press enter.

    Done!

    All the text in individual files will be copied to [newfile_name].txt

    0 讨论(0)
  • 2021-01-31 14:48

    In Win 7, navigate to the directory where your text files are. On the command prompt use:

    copy *.txt combined.txt
    

    Where combined.txt is the name of the newly created text file.

    0 讨论(0)
提交回复
热议问题