Contents
Is there a way to escape the unknown option in SED?
You need to escape it, or use a different delimiter. Additionally, you are needlessly stringing together multiple invocations where a single one would do. The cat is also useless. Unfortunately, not all sed dialects are compatible. If yours doesn’t like multiple -e options, try a single string of newline-separated sed commands.
What to do if your SED has multiple characters?
You have multiple / characters inside the $REPLY variable, which is confusing sed. You can choose an alternate delimiter for the s/// command in most versions of sed, so if this were me, I’d try something like: This replaces the / for sed with |, so that the / in $ {REPLY} are (hopefully) not interpreted by sed.
Is there an alternate delimiter for s / / / in SED?
You can choose an alternate delimiter for the s/// command in most versions of sed, so if this were me, I’d try something like: This replaces the / for sed with |, so that the / in $ {REPLY} are (hopefully) not interpreted by sed.
How to change Line 1 in Linux SED?
In the above file txt , I am intending to substitute /content/drive/Shared drives/Media Library in line 1 with the value of a variable path being read through a bash script . For example – If i enter /home/user as value of variable ,the line 1 in file.txt should be modified as follows :
Why are there no quotes in the sed command?
A second problem here is that if the sed command is surrounded by single quotes, the variable inside them does not get expanded. No quotes is even worse, as the shell attempts to perform word-splitting and glob expansion after the substitution.
When to use% instead of / in SED?
Use % instead of / in your sed. I guess your problem line has slashes in it and sed will strugle with it. Since you are using variables for the replace string, your slashes in there matters. My first answer was a bit missleading. Sorry for that. See the single quotes, you need four to take out the variable.
How to replace one string with another in SED?
# function: replaceCmd # globally replace one string with another using ed. # $1 is the filename, $2 is the string to match # $3 is the replacement string. strings are treated as regexes.