使用 sed 删除所有大于 6 个字符的单词 [英] Remove all words bigger than 6 characters using sed

查看:59
本文介绍了使用 sed 删除所有大于 6 个字符的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 sed 的新手,我正在尝试找出一种方法来删除超过 6 个字符的文本中的单词.

到目前为止我已经想出了这个,但它只是给了我一个空文件.

sed -n '/.\{6\}/!d' input >输出

<块引用>

输入

但是 sed 在管道中过滤文本的能力使其与其他类型的编辑器特别不同.

期望输出

但它是从其他类型的文本中提取出来的.

解决方案

这应该可以删除包含六个以上字母的单词 - 如果您将一个单词定义为由字母 A-Z 和 a-z 组成:

sed -e s'/[A-Za-z]\{7,\}//g'

I'm new to sed and I'm trying to figure out a way to remove the words in a text with more than 6 characters.

So far I've come up with this but it just gives me an empty file.

sed -n '/.\{6\}/!d' input > output

Input

But it is sed's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.

Desired output

But it is sed's to text in a which it from other types of.

解决方案

This should do the trick to remove words containing more than six letters - if you define a word as being made up of letters A-Z and a-z:

sed -e s'/[A-Za-z]\{7,\}//g'

这篇关于使用 sed 删除所有大于 6 个字符的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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