Reputation: 131
I want to append a colon character (:) at the end of the last line of a text file (not in a new line).
printf ":" >> file
puts the colon in a new line.sed '$s/$/:/' file > newfile
works, but my file is ~100 MB so piping the whole thing just to add a single character seems unattractive.Is there a better solution?
Upvotes: 2
Views: 1139
Reputation: 47099
You could go with dd
and notrunc
(tested on Linux 4.12):
printf ":" | dd of=file conv=notrunc bs=1 seek=$(( $(stat -c "%s" file) - 1))
Upvotes: 1