How do I ignore a special character in sed?
1 Answer
- You have a string in $DELETE_THIS , which you want to pass to sed in such a way that sed will treat it literally.
- For this, you must quote all characters which are meaningful to sed .
- Put a backslash before them. For example, using Bash syntax: DELETE_THIS=”$(<<< “$DELETE_THIS” sed -e ‘s`[][\\/.*^$]`\\&`g’)”
How to make SED ignore special charactars in Linux?
I have this line that I want to use sed on: where $start is not a varaiable, I want to use sed on it and replace all this line with: How can I make sed ignore special charactars, I tried adding back slash before special characters, but maybe I got it wrong, can some one show me an example? Add the -i (–inplace) to edit the input file.
What do characters do I need to escape when using SED?
\\ followed by a digit has a special meaning. \\ followed by a letter has a special meaning (special characters) in some implementations, and \\ followed by some other character means \\c or c depending on the implementation. With single quotes around the argument ( sed ‘s/…/…/’ ), use ‘\\” to put a single quote in the replacement text.
How to remove all lines containing special characters?
I need a sed command that will exclude these lines containing special character, numbers, or spaces. I’ve found that it is fairly straightforwards removing lines with spaces by using and I imagine that removing lines containing numbers will be a similar strategy using regex.
How to delete all lines in Bash using SED?
To delete any line that is not composed entirely of alphabetic characters, you’d need to add start ( ^) and end ( $) anchors Instead, you could delete any line that contains at least one non-alphabetic character Note that the caret ^ is acting as a negation operator here rather than as an anchor as in the previous expression.