Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge all .txt files in all subdirectories in one txt file

I want to merge content of all .txt files in my directory (containing subdirectories) to one txt file. I need to do this:

xcopy text1.txt + text2.txt text3.txt

but in a for loop which takes all text files in current directory. i assume something like this:

for \r ___ in ___ do copy list.txt

Thanks in advance.

like image 628
la lluvia Avatar asked Jan 31 '14 11:01

la lluvia


People also ask

How do I merge all text files?

Two quick options for combining text files. Open the two files you want to merge. Select all text (Command+A/Ctrl+A) from one document, then paste it into the new document (Command+V/Ctrl+V). Repeat steps for the second document. This will finish combining the text of both documents into one.

How do I combine multiple text files into one in Linux?

To join two or more text files on the Linux command-line, you can use the cat command. The cat (short for “concatenate”) command is one of the most commonly used commands in Linux as well as other UNIX-like operating systems, used to concatenate files and print on the standard output.

How do I merge the contents of multiple folders?

Open the parent folder which has the pictures/sub-folders. Use search to find all the image files (use operator kind:=picture) in ALL sub-folders. In the search results, select all files, right-click and choose "Cut". Paste everything in new folder.


2 Answers

Use one % instead of two %% to run it from the command line.

for /r "c:\folder" %%a in (*.txt) do type "%%a" >>"bigfile.txt"
like image 101
foxidrive Avatar answered Sep 25 '22 22:09

foxidrive


Try:

@echo off
set "folder=folder"
for /F %%a in ('dir /b /s %folder%') do (
 if "%%~xa" == ".txt" (
  (echo/------------------------------
  type %%~a
  echo/)>>"%~dp0list.txt"
)
)
like image 20
Rafael Avatar answered Sep 25 '22 22:09

Rafael