LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   replaceing \n with -e \n (https://www.linuxquestions.org/questions/linux-newbie-8/replaceing-%5Cn-with-e-%5Cn-4175577919/)

arun natarajan 04-20-2016 05:29 AM

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

grail 04-20-2016 06:06 AM

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.

pan64 04-20-2016 06:08 AM

you can use the same command in vim (so you can use ! as delimiter in vim too)

pan64 04-20-2016 06:11 AM

Code:

s! \\n! -e \\n!

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

...


Shadow_7 04-21-2016 11:07 AM

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.


All times are GMT -5. The time now is 11:17 AM.