如何使用sed删除尾随空格? [英] How to remove trailing whitespaces with sed?

查看:48
本文介绍了如何使用sed删除尾随空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 shell 脚本,可以从文件中删除尾随空格.有没有办法让这个脚本更紧凑(不创建临时文件)?

I have a simple shell script that removes trailing whitespace from a file. Is there any way to make this script more compact (without creating a temporary file)?

sed 's/[ \t]*$//' $1 > $1__.tmp
cat $1__.tmp > $1
rm $1__.tmp

推荐答案

感谢 codacci 建议使用 -i 选项.

Thanks to codaddict for suggesting the -i option.

下面的命令解决了Snow Leopard上的问题

The following command solves the problem on Snow Leopard

sed -i '' -e's/[ \t]*$//' "$1"

这篇关于如何使用sed删除尾随空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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