Torstein
Torstein

Reputation: 397

Prevent sed from adding newlines at the end of files

I have a large project where I want to replace module names using the following command:

find app/ -type f -exec sed -i '' 's/Foo/Bar/g' {} +

This works great, but sed also adds newlines to the end of all the files (even if it can't find any Foo's to replace).

How can I prevent sed from adding these newlines?

I'm on OSX, using the BSD version of sed.

(For the record, I very much agree with sed here, but I dont want to pollute the git history of the project.)

Upvotes: 8

Views: 1519

Answers (1)

choroba
choroba

Reputation: 241918

Perl to the rescue:

perl -i -pe 's/Foo/Bar/g'

Perl doesn't add newlines.

Upvotes: 8

Related Questions