0

We have a ASCII art like the following

ART  _____                            
ART |  __ \               
ART | |__) |__  ___ _ __   
ART |  ___/ _ \/ _ \ '__|  
ART | |  |  __/  __/ |    
ART |_|   \___|\___|_|     
ART                        
ART                        

We have a variable ${art}="123456" and want to replace ART with ${art}, so the system will print the standard output like this

123456  _____                            
123456 |  __ \               
123456 | |__) |__  ___ _ __   
123456 |  ___/ _ \/ _ \ '__|  
123456 | |  |  __/  __/ |    
123456 |_|   \___|\___|_|     
123456                        
123456                       

I have tried this as this post suggests

sed -i "s/ART/${art}/g" ascii-art 

The following error message shows up:

sed: -e expression #1, char 6: unterminated `s' command

I am in 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 returns:

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: <[email protected]>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.

Any thoughts?

Thanks!

8
  • Works fine for me. Try sed -i"" "s/ART/${art}/g" ascii-art - note the extra quotes after -i. Commented Jul 14, 2017 at 22:25
  • This would happen if the value of $art contains a / character. But 123456 shouldn't be a problem. Commented Jul 14, 2017 at 22:27
  • 1
    @SiKing There's no difference between -i and -i"". An empty string is simply removed by the shell. Commented Jul 14, 2017 at 22:28
  • works fine for me sed -i 's/ART/${art}/g' <filename> Commented Jul 14, 2017 at 22:29
  • Add the output from sed --version to your post. Commented Jul 14, 2017 at 22:31

1 Answer 1

1

If $art contains /, you might need to backslash it or use a different delimiter.

Or, use Perl:

perl -i -pe 's/ART/$ENV{art}/g' -- file

this will work when $art is exported, if it isn't, just export it for the command:

art=$art perl ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.