BB Locks
BB Locks

Reputation: 35

Add a period two characters from the end of each line

What is the best way to add a period two characters from the end of each line in a txt file using sed? Other options are also welcomed.

199801_Track_1.1 xx 303
199801_Track_1.2 xx 264
199801_Track_1.3 xx 92
199801_Track_1.4 xx 61
199801_Track_1.5 xx 402

becomes

199801_Track_1.1 xx 3.03
199801_Track_1.2 xx 2.64
199801_Track_1.3 xx .92
199801_Track_1.4 xx .61
199801_Track_1.5 xx 4.02

I have 2500 lines in a text file and each line ends in either two or three random digits. Thanks

Upvotes: 2

Views: 740

Answers (1)

bkmoney
bkmoney

Reputation: 1256

You can use

sed 's/..$/.&/' file

This substitutes the two characters at the end of the line, which is matched by ..$, with a period and then the matched pattern, which is denoted by &.

Upvotes: 7

Related Questions