OXXO
OXXO

Reputation: 724

Adding a dot in the last line of a file

I want to add a dot (full stop) in the last line (last character) of the file

The file:

AAAAAA              21,28,22-23,35,24-27,29-30,37,31-34,36,54,38-45,47,46,48-53,
AAAAAA              71,55-70,72-78,80,79,81-93,96,94-95,97-98,100,99,101-103,
AAAAAA              122,104-114,118,115-117,119-121,123-124,140,125-130,148,
AAAAAA              1649-1650,1652-1667,1669-1853

Desired output

AAAAAA              21,28,22-23,35,24-27,29-30,37,31-34,36,54,38-45,47,46,48-53,
AAAAAA              71,55-70,72-78,80,79,81-93,96,94-95,97-98,100,99,101-103,
AAAAAA              122,104-114,118,115-117,119-121,123-124,140,125-130,148,
AAAAAA              1649-1650,1652-1667,1669-1853**.**

My code:

sed '$d' file > tmp1
tail -1 file > tmp2
sed -i 's/$/./' tmp2

cat tmp1 tmp2 > output

I got the desired output with the code above.
Is there a more efficient way to solve this problem?

Upvotes: 1

Views: 946

Answers (2)

storm
storm

Reputation: 409

You can use echo , this will work only if your last line doesn't already contains a carriage return

echo -n "." >> file

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799210

Tell sed to only change the last line.

sed '$s/$/./'

Upvotes: 5

Related Questions