empty line appears while merging different file contents in shell script

97 views Asked by At

I wrote a shell script to merge some files' contents. I created directories f1,f2,d1,d2, and files under those, and need to merge all the files contents:

f1 has file with contents "--this is new text from f1 ----"
f2 -- " --this is text from f2 ----"    
d1 -- " --this is new text from d1 ---"
d2 -- "---this is new text from d2 ---"

Script is:

#!/bin/bash
find /home/me/f1  /home/me/f2  /home/me/d1  /home/me/d2  \
    -type f \
    -exec cat {} \; \
    -exec echo \; > /home/me/result/op.txt

The output is :

--this is new text from f1 ----

--this is text from f2 ----
--this is new text from d1 ---
---this is new text from d2 ---
--this is new text from f1 ----

--this is text from f2 ----
---this is new text from d2 ---

After file f1's contents, it adds one empty line. I want merged contents without any empty lines in between. What are the changes I need to do in the above command? Any help would be appreciated in advance.

0

There are 0 answers