shell - How to merge multiple files into single file in given directories -
i want write shell script merge contents of multiple files in given directories.
dir1 contains sample1.txt sample2.txt sample1.txt contents :---this sample1 file sample2.txt contents :---this sample2 file dir2 contains demo1.txt demo2.txt demo1.txt contents :---this demo1 file
i tried :
(find /home/dir1 /home/dir2 -type f | xargs -i cat {} ) > /result/final.txt
it worked!
this sample2 file sample1 file demo1 file
however output appears in single line need every file's output in separate new line. this:
this sample1 file sample2 file demo1 file
how achieve this?
any appreciated in advance.
your files don't end newlines, , therefor there no newlines in output file.
you should either make sure input files end newlines, or add them in find
command:
find /home/dir1 /home/dir2 -type f -exec cat {} \; -exec echo \;
Comments
Post a Comment