File concatenation problem

I have written a script to find particular text files created within the last 24 hours and concatenate them all into a single concat.txt file. The problem that I am running into is that the last line of the text files do not terminate with <CR><LF> characters (as do all the other lines in each file). The lack of line termination characters at the end of the last lines causes the files to 'wrap' together: line1 of file2 is appended to the end of the last line of file1, and line 1 of file3 is appended to the end of file 2, etc. (This file format has given me alot grief overall with other things, since for instance tail doesn't work right if line don't have \n at the end, etc.)

Anyway, to resolve this, I wrote the code below to append a <newline> character to the end of each file as files are concatenated. This works except that it results in a single blank line between each file, that I have to remove using sed. I don't understand why I'm getting blank lines since without the added \n, the lines wrapped together.

Here's my code:

find ${ARCH_DIR} -name 'AA20*txt' -ctime -${DAYSCNT} -exec cat {} \; -exec echo "\n" \; >> ${CATFILENAME}

sed '/^$/d' $CATFILENAME > $TEMPFILE

Is there an easier and better way to concatenate text files that have no line termination characters at the end of the last line, especially one that doesn't add blank lines?

Any help would be much appreciated.

maybe something like this - not tested:

find ${ARCH_DIR} -name 'AA20*txt' -ctime -${DAYSCNT} \; | xargs -l (cat; echo '')>> ${CATFILENAME}

echo is adding two carriage returns - one for the character.

change echo "\n" to echo " " or change the parms to echo to suprress the second \n

I changed the echo to echo "" and it works great. Thanks VERY much! :wink: :slight_smile: