使用sed删除文本文件中的所有前/后空格 [英] Use sed to delete all leading/following blank spaces in a text file

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

问题描述

文件1:

  hello  
  world  

如何使用sed删除此文件中的前导/后缀空格-使用一个命令(无中间文件)?

How would one delete the leading/trailing blank spaces within this file using sed - using one command (no intermediate files)?

我目前有:

sed -e 's/^[ \t]*//' a > b

对于前导空格.

sed 's/ *$//' b > c

这用于尾随空格.

推荐答案

您几乎明白了:

sed -e 's/^[ \t]*//;s/[ \t]*$//' a > c

此外,除了sed的某些样式外,还有一个用于内联编辑的选项:

Moreover on some flavours of sed, there is also an option for editing inline:

sed -i -e 's/^[ \t]*//;s/[ \t]*$//' a

这篇关于使用sed删除文本文件中的所有前/后空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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