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

查看:21
本文介绍了使用 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/^[ 	]*//' a > b

用于前导空格.

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

这用于尾随空格.

推荐答案

你差不多明白了:

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

此外,在 sed 的某些风格上,还有一个用于编辑内联的选项:

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

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

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

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