Paul
Paul

Reputation: 80

Using sed, I need to replace all ",\n" with ",\.\n" including the last line

I have several thousand large text files that I need to clean up. I need any line that ends with a comma to end with a comma followed by a period (,.).

I found the following, which works for every line except the last line. It must be close to what I need but I can't figure out how to make it work on the last line as well.

find . -name "*.txt" -print  | xargs sed -i ':a;N;$!ba;s/,\n/,\.\n/g'

My data looks something like this:

0,0,0,193,17,.,.,
0,0,0,174,19,.,.,
0,0,0,124,14,.,.,

I need it to look like this:

0,0,0,193,17,.,.,.
0,0,0,174,19,.,.,.
0,0,0,124,14,.,.,.

Upvotes: 1

Views: 215

Answers (1)

Fred Foo
Fred Foo

Reputation: 363687

sed 's/,$/,./'

($ means end of line.)

Upvotes: 3

Related Questions