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?
- 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.
- A solution that adds the cr/fl only to files that do not already end that way.
while
is skipping those broken last lines. – thrig Feb 16 '17 at 19:25\n
? On *nix systems, lines end with a single\n
. The\r\n
is a Windows thing. And where do you want this? At the end of each line? The end of the file? – terdon Feb 16 '17 at 19:45find
; yes, infind
, the%s
ofprintf
is the size of the file. But that's a peculiarity offind
. Theprintf
utility is very standard and exists (behaving more or less the same way) in shells and most programming languages. There,printf '%s' foo
will just replace the%s
withfoo
and print it. – terdon Feb 16 '17 at 21:06