InterviewSolution
| 1. |
How Do I Replace "/some/unix/path" In A Substitution? |
|
Answer» Technically, the normal meaning of the slash can be disabled by PREFIXING it with a BACKSLASH. Thus, sed 's//some/UNIX/path//a/new/path/g' files But this is hard to read and write. There is a BETTER solution. The s/// SUBSTITUTION command allows '/' to be replaced by any other character (INCLUDING spaces or alphanumerics). Thus, sed 's|/some/UNIX/path|/a/new/path|g' files and if you are using variable names in a Unix shell script, sed "s|$OLDPATH|$NEWPATH|g" oldfile >newfile Technically, the normal meaning of the slash can be disabled by prefixing it with a backslash. Thus, sed 's//some/UNIX/path//a/new/path/g' files But this is hard to read and write. There is a better solution. The s/// substitution command allows '/' to be replaced by any other character (including spaces or alphanumerics). Thus, sed 's|/some/UNIX/path|/a/new/path|g' files and if you are using variable names in a Unix shell script, sed "s|$OLDPATH|$NEWPATH|g" oldfile >newfile |
|