LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 05:29 AM   #1
arun natarajan
Member
 
Registered: Jun 2014
Posts: 108

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, 06:06 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,544

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
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, 06:08 AM   #3
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,673

Rep: Reputation: 2855Reputation: 2855Reputation: 2855Reputation: 2855Reputation: 2855Reputation: 2855Reputation: 2855Reputation: 2855Reputation: 2855Reputation: 2855Reputation: 2855
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, 06:11 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,673

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

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

...
 
Old 04-21-2016, 11:07 AM   #5
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 3,251
Blog Entries: 1

Rep: Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681Reputation: 681
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 08:03 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:54 PM.

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