LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-20-2016, 06:29 AM   #1
arun natarajan
Member
 
Registered: Jun 2014
Posts: 96

Rep: Reputation: Disabled
replaceing \n with -e \n


hi

am trying to replace "echo \n" as echo "echo -e \n" througout my script, which is not working as expected.

my work around:

:%s//n/-e /n/g
:%s/"/n"/"-e /n"/g
:%s/\/n/-e \/n/g
:%s:\/n:-e \/n:g
 
Old 04-20-2016, 07:06 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,250

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
You say you want to replace '\n' but all of your examples are trying to replace '/n'. I would also suggest that most of your examples would error due to the excess of /'s

Based on your examples I presume you are performing the task inside vim and whilst it can be done there, sed would probably be cleaner as you can change the /// delimiter for another character
to make it clear what you are doing.
 
Old 04-20-2016, 07:08 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,109

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
you can use the same command in vim (so you can use ! as delimiter in vim too)
 
1 members found this post helpful.
Old 04-20-2016, 07:11 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,109

Rep: Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268Reputation: 2268
Code:
s! \\n! -e \\n!

s!echo .n!echo -e \\n!

...
 
Old 04-21-2016, 12:07 PM   #5
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 2,324
Blog Entries: 1

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Quote:
Originally Posted by arun natarajan
am trying to replace "echo \n" as echo "echo -e \n" througout my script, which is not working as expected.
So either...

$ echo -e $(echo -e \n)

or

$ echo echo -e \\n

Bash will interpret things before passing them to a command. Hence the double \ to maintain the single \ after interpretation.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Redhat Shrike replaceing wyse terminals toucan Linux - Server 6 04-05-2011 09:03 PM


All times are GMT -5. The time now is 04:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration