sed: Insert a string containing path delimeters
By John Parsons •
I want to insert a line into a file at line 13 using sed. This is what I tried:
sed -i '13/home/me/dostuff.py &' /etc/rc.localI get this error:
sed: -e expression #1, char 3: unknown command : `/'How do I insert text containing slashes at a given line using sed?
1 Answer
Use
sed -i '13i\/home/me/dostuff.py &' /etc/rc.localto insert it (i.e. place it before line 13); or
sed -i '13a\/home/me/dostuff.py &' /etc/rc.localto append it (i.e. place it after the current line 13).
Note that forward slashes aren't special in sed's i and a commands - only in regular expression matches such as /pattern/d or s/pattern/replacement/ (although even there, they may be replaced by other delimiters such as \%pattern%d or s#pattern#replacement# - at least in GNU sed).