How to Merge TXT files with Command Line: 4 Steps

Table of contents:

How to Merge TXT files with Command Line: 4 Steps
How to Merge TXT files with Command Line: 4 Steps

Video: How to Merge TXT files with Command Line: 4 Steps

Video: How to Merge TXT files with Command Line: 4 Steps
Video: Reset SA password in SQL Server 2024, May
Anonim

You can combine text files stored in the same folder with a simple command. This merge can help you organize dictionaries, word lists, or files in folders.

Step

Merge Text (. Txt) Files in Command Prompt Step 1
Merge Text (. Txt) Files in Command Prompt Step 1

Step 1. Open the folder containing the TXT files that you want to merge

Merge Text (. Txt) Files in Command Prompt Step 2
Merge Text (. Txt) Files in Command Prompt Step 2

Step 2. Click an empty space in the folder window to make sure no files are selected

Hold down the Ctrl and Shift keys, then right-click an empty space in the window.

Merge Text (. Txt) Files in Command Prompt Step 3
Merge Text (. Txt) Files in Command Prompt Step 3

Step 3. Click Open command window here to open a command line window in the folder you are currently opening

That way, you can continue the merging process.

If the above options do not appear, use the Start menu to search for "cmd", and open Cmd.exe (or enter cmd in the Run dialog box if you are using Windows XP). Once open, enter the command cd C:\ and go to the directory where the file is stored. For example, if you have a directory named Files on your desktop, enter cd C:\Users\username\Desktop\files. Replace "username" with your username on the computer

Merge Text (. Txt) Files in Command Prompt Step 4
Merge Text (. Txt) Files in Command Prompt Step 4

Step 4. After pointing the command line window to the appropriate directory, enter the command for %f in (*.txt) do type "%f" >> output.txt

This command will select all the files with the TXT extension in the directory and combine them into a single file named "output.txt". Rename the file as desired.

In the command, a new line will also be added after the computer has successfully read a file. The newline is needed because the file that has been read will be merged to the last line of the new file

Tips

  • Save the merged file in another folder, or use an extension other than TXT to prevent repeating the command.
  • If you don't want to manually type the above command, you can copy the command and paste it in the command line window by right-clicking and selecting Paste.
  • You can delete text files that you no longer need after making sure that all the files have been merged.

Warning

  • Do not try this command on other operating systems, such as Mac OS X or Linux because the commands that each operating system receives are different. However, you can still try it at your own risk.
  • Make sure the command line window points to the directory containing the text files. If you accidentally run this command outside the directory, you may accidentally merge all text files on your computer. This process will slow down the computer considerably or cause the computer to experience errors.
  • The location of the file storage folder will vary depending on the operating system and computer you are using. Be careful when using the CD command.

Recommended: