1

I have hundreds of folders with a few text files in each folder. I'm trying to concatenate the files of each folder into a single text file. One file for each folder. Ideally, the concatenated files would be saved to another location.

2

You can do with a simple script:

#!/bin/bash

directories="/your/path/dir1 /your/path/dir2 /your/path/dir3"

for d in $directories
do
        cat $(find $d -name "*.txt") > $(echo $d | sed 's/\///g').txt
done

This script will concatenate every txt file on /your/path/dir1 and saves it as yourpathdir1.txt in your actual path. Then will do the same with dir2 and dir3.

  • Thanks @jherran. Unfortunately it doesn't seem to be working. I get the following error"/My/path/file.txt/\: No such file or directory". Man wish I know this stuff better, I feel like you've gotten me really close. – yogert909 Nov 25 '14 at 1:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .