Yiorgos
Yiorgos

Reputation: 131

Append text to the last line of a file in unix

I want to append a colon character (:) at the end of the last line of a text file (not in a new line).

Is there a better solution?

Upvotes: 2

Views: 1139

Answers (1)

Thor
Thor

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

Related Questions