User Tools

Site Tools


sed:new_line

SED - New line

Neither \s* (as I would use in javascript and php) nor \s\{3,\} works.

Note too that \n is not recognized as a new line. To get a new line \'$'\n must be used.

To modify the .profile file.

#sed -i .bak  's/^\(export[ ]*JAVA_HOME.*\)/#&\'$'\nexport\ JAVA_HOME=\/Users\/${USER}\/\.java_jdk_6\/soylatte16-i386-1\.0\.3/' ~/.profile
#sed -i .bak  's/^\(export[ ]*JAVA_HOME.*\)/&\'$'\nexport\ PATH=${JAVA_HOME}\/bin:$PATH/' ~/.profile  

The two lines above did what I wanted but the second line did a backup of the modified ~/.profile. So I came up with the next solution.

sed -i .bak  's/^\(export[ ]*JAVA_HOME.*\)/#&\
\export\ JAVA_HOME=\/Users\/${USER}\/\.java_jdk_6\/soylatte16-i386-1\.0\.3\
\export\ PATH=${JAVA_HOME}\/bin:$PATH/' ~/.profile

The new line is achieved by ending a regex with \ and continuing it with \ on the next line. If there are white spaces in front of \ they will also appear in ~/.profile.

sed/new_line.txt · Last modified: 2020/07/15 09:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki