从txtfiles删除空行,从开始和行末删除空格 [英] Remove empty lines from txtfiles, remove spaces from start and end of line

查看:131
本文介绍了从txtfiles删除空行,从开始和行末删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这将是一个更好的:

  SED -e / ^ $ / d的* .TXT
SED'克/ ^ $ / D'-i * .TXT

我如何删除从开始并在文本文件中的每一行的末尾空格?


解决方案

  $ SED的/ ^ * //; S / * $ //; / ^ $ / D'file.txt的`S / ^ * //`=>左装饰
`S / * $ //'=>正确的修剪
`/ ^ $ / D` =>删除空行

Which would be a better:

sed -e /^$/d *.txt
sed 'g/^$/d' -i *.txt

How do i remove spaces from beginning and end of each lines in the text file?

解决方案

$ sed 's/^ *//; s/ *$//; /^$/d' file.txt

`s/^ *//`  => left trim
`s/ *$//`  => right trim
`/^$/d`    => remove empty line

这篇关于从txtfiles删除空行,从开始和行末删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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