I want to concatenate multiple files recursively from sub-directories intoone file in Linux.
I saved the following script as script.sh in $HOME/testing1 where I have several subdirectories and .txt files into them. I ran script.sh from the command prompt of $HOME/testing1 as ./script.sh. But it deleted all the files from my sub-directories. Can anybody tell me what was wrong and write the correct script for me?
The only messages I got:
Code:
cat: file11.txt: input file is output filecat: file22.txt: input file is output file............
Here is the script I have used:
ogdir=$HOME/testing1 ## adjust to tastefor dir in "$logdir"/*/do(cd "$dir"files=( *.txt )cat "${files[@]}" > "${PWD##*/}.txt"rm "${files[@]}")done
---------- Post updated at 01:31 PM ---------- Previous update was at 01:29 PM ----------
I want to concatenate multiple files recursively from sub-directories into one file in Linux.
I saved the following script as script.sh in $HOME/testing1 where I have several subdirectories and .txt files into them. I ran script.sh from the command prompt of $HOME/testing1 as ./script.sh. But it deleted all the files from my sub-directories. Can anybody tell me what was wrong and write the correct script for me?
The only messages I got:
cat: file11.txt: input file is output file
cat: file22.txt: input file is output file
Here is the script I have used:
l
ogdir=$HOME/testing1 ## adjust to taste
for dir in "$logdir"/*/
do
(
cd "$dir"
files=( *.txt )
cat "${files[@]}" > "${PWD##*/}.txt"
rm "${files[@]}"
)
done