Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm using

find . -type f \( -name "*.js" ! -name "*-min*" \) -exec cat {} \; > all.js

to merge files together. Unfortunately I don't get a new line after each file but it ends and the new file starts on the same line.

How can I add a newline between each file?

share|improve this question
add comment

3 Answers

up vote 4 down vote accepted

The script below will do the task

find . -type f \( -name "*.js" ! -name "*-min*" \) | while IFS= read -r line
do
   cat "$line"
   echo
done >all.js
share|improve this answer
    
Perfect! Will accept in 3 min ;) –  Asken Sep 5 '12 at 10:39
add comment

If you want to systematically add a newline after each file:

find . -type f \( -name "*.js" ! -name "*-min*" \) \
     -exec cat {} \; -exec echo \; > all.js

or

find . -type f \( -name "*.js" ! -name "*-min*" \) \
     -exec sh -c 'for x; do cat "$x"; echo; done' _ {} + >all.js

If you want to add a newline at the end of each file that doesn't end with a newline:

find . -type f \( -name "*.js" ! -name "*-min*" \) \
     -exec awk '1' {} + > all.js
share|improve this answer
    
Above and beyond! Thanks! –  Asken Sep 7 '12 at 9:40
add comment

You can also do this way:

find source/path -name *.js | xargs cat > all.js

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.