Sample Header Ad - 728x90

How to cat files together, adding missing newlines at end of some files

30 votes
7 answers
31505 views
I have a bunch of .text files, _most_ of which end with the standard nl. A couple don't have any terminator at end. The last physical byte is (generally) an alphameric character. I was using cat *.text >| /tmp/joined.text, but then noticed a couple of places in joined.text where the first line of a file appeared at the end of the last line of a previous file. Inspecting the previous file, I saw there wasn't a line terminator -- concatenation explained. That raised the question, what's the easiest way to concatenate, sticking in the missing newline? What about these options? 1. A solution that might effectively add a blank line to some input files. For me, that's not a problem as the processing of joined.text can handle it. 2. A solution that adds the cr/fl only to files that do not already end that way.
Asked by HiTechHiTouch (991 rep)
Feb 16, 2017, 07:17 PM
Last activity: Jul 23, 2025, 10:22 AM