Escape sequence
HI All,
I'm trying to remove the special meaning of the forward slash (/) in the below all at once " Code:
utap:2345:respawn:/usr/local/guardium/guard_stap/guard_stap /usr/local/guardium/guard_stap/guard_tap.ini Code:
sed -i "/utap:2345:respawn:\/usr\/local\/guardium\/guard_stap\/guard_stap/d" test1 |
Keep going with the escapes or was there a question I am missing here? Ultimately you are saying there is a chance of another lines being almost identical hence you need to put the entire line in. If this
is the case, then you have no other choice but to escape all the back slashes and perhaps even the period. |
You can play games with the "s" command, which can use any character as the delimiter, and the "T" command, which will branch if no substitution was done:
Code:
sed -i "s@/utap:2345:respawn:/usr/local/guardium/guard_stap/guard_stap/@anything@;T;d" test1 However, you still have to watch out for any regex wildcards in the string. Those might cause a false match (e.g., ".") or prevent a match (e.g., looking for a literal "*"). You still have to escape any of those. You might find "grep -F -v" to be a better choice, though there's no "in-place" option there. |
Depending on the source file, you could match fewer things.
Eg if a line containing "guard_stap" is unique Code:
sed -i '/guard_stap/d' test1 |
Please excuse me for poorly wording my question earlier. Let me rephrase it. What I'm trying to do is, say to the system that "Hey system, take this text utap:2345:respawn:/usr/local/guardium/guard_stap/guard_stap/and remove the special meaning of the special characters which in this case is mostly /, consider it just as regular text and process it. But I want to do that in the sed command like below".
Code:
sed -i "\(utap:2345:respawn:/usr/local/guardium/guard_stap/guard_stap)/d" test1 |
I think we all pretty much hit that nail and as I said, if there are possibly more lines containing the same string in almost its entirety then you will need to put in the entire line and if using the '/d'
option then you will have to escape all the slashes. As pointed out by rknichols an alternative would be you could leave the line empty instead of deleting it with something like: Code:
sed -i 's@utap:2345:respawn:/usr/local/guardium/guard_stap/guard_stap@@' file Code:
sed -i '/^utap:2345:respawn:.*guard_stap/d' file |
in sed you can use different delimiters as it was described in post #3, that is a bit tricky, but was explained well (at least for me).
From the other hand there is another trick I used to "employ": just write dot instead of special chars, so: Code:
sed '/utap:2345:respawn:.usr.local.guardium.guard_stap.guard_stap/d' Perl has very nice functions to escape special chars in one Code:
check: Code:
sed 's/\([/*?]\)/\\\1/g' |
Quote:
In your source file (inittab ?), there are more than one line containing ' */guard_stap '? If yes, you want to keep some of these lines or delete all of them? |
All times are GMT -5. The time now is 12:01 PM. |