regex - Sed replace string with multi-lines -


i have simple sed command:

#!/bin/bash command=$1 sed -e "s#command#$command# 

the value command should new line every command cannot figure out how give them sed , sed put every command on new line. have tried is:

 ./script 'ls\n date\n uname\n' 

regards!

if i'm understanding question, looking replace representation of newlines within string (i.e. backslash character, followed 'n') actual printed newlines.

the following script takes single quoted string (the input shown in question) containing literals '\n' , converts actual new lines.

#!/bin/bash echo -n $1 | sed -e 's#\\n#\n#g' 

example usage:

[user@localhost ~]$ ./simple_sed.sh 'ls\ndate\nuname\n'  ls date uname 

the changes needed script

    1. echo argument, otherwise sed expects file , nothing;
    1. match \\n , replace newline; ,
    1. add 'g' end continue searching within line after replacement has occurred (read: multiple \n substituted in single line).

Comments

Popular posts from this blog

Capture and play voice with Asterisk ARI -

c++ - Can not find the "fiostream.h" file -

visual studio - Installing Packages through Nuget - "Central Directory corrupt" -