sed:如何从每行开头删除选定数量的空格(制表符) [英] sed : how remove selected number of white spaces (tabs) from beginning of each line

查看:56
本文介绍了sed:如何从每行开头删除选定数量的空格(制表符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 python 示例代码,每行开头有 6 个白色无用空格.

I have some python sample code with 6 white useless spaces in the beginning of each line.

我有这个代码来删除所有空格...

I have this code to remove all white spaces...

sed 's/^[ \t]*//;s/[ \t]*$//'

但是如何删除指定数量的空格(在我的情况下为 6)?

But how to remove just specified number of white spaces ( in my case 6) ?

推荐答案

将我的评论转换为答案,以便将来的访问者轻松找到解决方案.

Converting my comment to answer so that solution is easy to find for future visitors.

这个 sed 应该适合你(根据你的评论):

This sed should work for you (based on your comments):

sed -E 's/^[[:blank:]]{19}//;s/[[:blank:]]+$//' file

要在线保存更改:

sed -i.bak -E 's/^[[:blank:]]{19}//;s/[[:blank:]]+$//' file

这篇关于sed:如何从每行开头删除选定数量的空格(制表符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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