Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recursively cat all the files into single file

I have bunch of files sitting in folders like

data\A\A\A\json1.json data\A\A\A\json2.json data\A\A\B\json1.json ... data\Z\Z\Z\json_x.json 

I want to cat all the jsons into one single file?

like image 732
frazman Avatar asked Jun 05 '14 19:06

frazman


People also ask

How do I cat all files in a folder?

You can use the * character to match all the files in your current directory. cat * will display the content of all the files.

How do I combine all texts into one file 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 combine multiple files into one in Unix?

Replace file1 , file2 , and file3 with the names of the files you wish to combine, in the order you want them to appear in the combined document. Replace newfile with a name for your newly combined single file.

How do I combine multiple files into one in Linux?

Appending content to an existing file To append content after you merge multiple files in Linux to another file, use double redirection operator. (>>) along with cat command. Rather than overwriting the contents of the file, this command appends the content at the end of the file.


1 Answers

find data/ -name '*.json' -exec cat {} \; > uber.json 

a short explanation:

find <where> \   -name <file_name_pattern> \   -exec <run_cmd_on_every_hit> {} \; \     > <where_to_store> 
like image 77
Pavel Avatar answered Sep 19 '22 23:09

Pavel