长度相等的替代文字使用的sed [英] substitute text with equal length using sed

查看:99
本文介绍了长度相等的替代文字使用的sed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,以取代别人出头(例如点,零点等)的长度相等的模式使用sed的?
像这样的:

Is there a way to replace a pattern with equal length of somethings else (e.g. dots, zeros etc.) using sed? Like this:

maci:/ san$ echo "She sells sea shells by the sea shore" | sed 's/\(sh[a-z]*\)/../gI'
.. sells sea .. by the sea ..

我需要的sed忽略大小写的更新的版本)结果
这是很简单:以嘘开始字由双点(..),但我怎么做更换
它是这样的: ...在海边卖海...... .....

你知道吗?干杯!

推荐答案

这可能会为你工作(GNU SED):

This might work for you (GNU sed):

sed -r ':a;/\b[Ss]h\S+/!b;s//\n&\n/;h;s/.*\n(.*)\n.*/\1/;s/././g;G;s/(.*)\n(.*)\n.*\n/\2\1/;ta' file

在本质;它复制一个字开头的 SH ,替换每个字符与,然后重新插入新的字符串放回原处。当搜索字符串出现的所有已用尽它打印出来就行了。

In essence; it copies a word beginning with sh or Sh, replaces each character with . and then re-inserts the new string back into the original. When all occurences of the search string have been exhausted it prints out the line.

这篇关于长度相等的替代文字使用的sed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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