如何在bash中的两个模式之间替换所有字符?
我希望替换以(并以)为单位=符号开始的可变长度线的所有字符。
示例:
line1 with some words
( + + + + + + )
line3 with some words
应该更改为:
line1 with some words
=====================
line3 with some words
它尝试了以下bash代码,但它不起作用,因为它也更改了Line1和Line3中的白色空间:
echo -e "line1 with some words\n( + + + + + + )\nline3 with some words"|tr ' (+)' '='
结果:
line1=with=some=words
=====================
line3=with=some=words
我需要修复什么才能使其正常工作?
I'm looking to replace all chars of a line of variable length starting with ( and ending with ) by = symbols.
Example:
line1 with some words
( + + + + + + )
line3 with some words
should be changed to:
line1 with some words
=====================
line3 with some words
It tried the following bash code, but it doesn't work, as it also changes white spaces in line1 und line3, too:
echo -e "line1 with some words\n( + + + + + + )\nline3 with some words"|tr ' (+)' '='
Result:
line1=with=some=words
=====================
line3=with=some=words
What do I need to fix in order to make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果一行以
开头(
,并以>)结束,则在此行中替换为
=
的所有字符。If a row starts with
(
and ends with)
then replace in this row all characters with=
.假设:
>(
和/或之后)可能还有其他字符())示例输入:
一个
awk
构想:这生成:
Assumptions:
(
and/or after the)
Sample input:
One
awk
idea:This generates: