I have a directory structure
DIR SUBDIR1 11-01-11.txt 13-05-23.txt SUBDIR2 12-05-56.txt 13-04-02.txt 15-04-06.txt
I would like to write a bash script that leads to this Desired output
DIR SUBDIR1 sub_dir1_merged.txt SUBDIR2 sub_dir2_merged.txt
I would like to maintain the original directory structure, merge files into a single sub_dirname_merged.txt file for each and delete all original files.
I tried the following code
for f in */ do cat $f/*.txt > "$f"/$f_merged.txt rm $f/*.txt done
this does not work fully.