【发布时间】:2017-12-20 02:37:14
【问题描述】:
我们有一个像下面这样的 ASCII 艺术
ART _____
ART | __ \
ART | |__) |__ ___ _ __
ART | ___/ _ \/ _ \ '__|
ART | | | __/ __/ |
ART |_| \___|\___|_|
ART
ART
我们有一个变量${art}="123456",想用${art}替换ART,所以系统会这样打印标准输出
123456 _____
123456 | __ \
123456 | |__) |__ ___ _ __
123456 | ___/ _ \/ _ \ '__|
123456 | | | __/ __/ |
123456 |_| \___|\___|_|
123456
123456
我已经按照这篇文章的建议尝试过
sed -i "s/ART/${art}/g" ascii-art
出现以下错误信息:
sed: -e expression #1, char 6: unterminated `s' command
我在Linux ip-10-22-37-149 4.4.8-20.46.amzn1.x86_64 #1 SMP Wed Apr 27 19:28:52 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux (Amazon EC2)
sed --version 返回:
GNU sed version 4.2.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <bug-gnu-utils@gnu.org>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.
有什么想法吗?
谢谢!
【问题讨论】:
-
对我来说很好。试试
sed -i"" "s/ART/${art}/g" ascii-art- 注意 -i 之后的额外引号。 -
如果
$art的值包含/字符,就会发生这种情况。但是123456应该不是问题。 -
@SiKing
-i和-i""之间没有区别。空字符串会被 shell 简单地删除。 -
对我来说很好
sed -i 's/ART/${art}/g' <filename> -
将
sed --version的输出添加到您的帖子中。