防止sed在文件末尾添加换行符 [英] Prevent sed from adding newlines at the end of files

查看:120
本文介绍了防止sed在文件末尾添加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型项目,我想使用以下命令替换模块名称:

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' {} +

这很好用,但是sed还在所有文件的末尾添加了换行符(即使它找不到要替换的Foo).

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).

如何防止sed添加这些换行符?

How can I prevent sed from adding these newlines?

我在OSX上,使用的是sed的BSD版本.

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

(出于记录,我非常同意sed在这里,但我不想污染该项目的git历史.)

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

推荐答案

Perl进行救援:

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

Perl不会添加换行符.

Perl doesn't add newlines.

这篇关于防止sed在文件末尾添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆