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
- echo argument, otherwise sed expects file , nothing;
- match \\n , replace newline; ,
- add 'g' end continue searching within line after replacement has occurred (read: multiple \n substituted in single line).
Comments
Post a Comment