开发者

Replacing the character by deli meter based on length in SED script

开发者 https://www.devze.com 2023-03-23 02:02 出处:网络
I want to achieve following things in sed script. I tried with greedy operatorit does not works as i expected. for reference

I want to achieve following things in sed script. I tried with greedy operator it does not works as i expected. for reference

:loop
s#\(S\)\(.\)\(.*R\)#-\n\1\3\n#
t loop
s#SR#--#
s#\n##g 

If the pattern has FlowerR this should be replaced by number -------

If the pattern hash FoR this should be rep开发者_如何转开发laced by ---

So the number replace character is equal to matched pattern length which between F and R


$ echo "a FloweR has FaR FeweR FlaiR" | perl -pe 's{F.*?R}{"-" x length $&}eg'
a ------ has --- ----- -----
0

精彩评论

暂无评论...
验证码 换一张
取 消