Oscar Sayin Oscar Sayin - 1 year ago 169
Bash Question

Insert a text before slash "/" character in bash scripts

I have a line in a file as below:

2 14 * * * /run/opt/server/autoi.sh

And I want to insert "root" before /run/opt/server/autoi.sh as below:

2 14 * * * root /run/opt/server/autoi.sh

I have tried the following command

sed '//run/i root' filename

but it gives the following error:

sed: -e expression #1, char 0: no previous regular expression

Could you please help me to find a fix for it?

Answer Source

Use a different separator character, and you need to use the s command to substitute, e.g:

sed '[email protected]/[email protected] /[email protected]' filename

or without repeating /run:

sed '[email protected]/[email protected] &@' filename
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download