Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
For regular sed, only the backslash is a meta-character, and needs to be escaped.
sed 's/{\\{}}//g' file >modified-file
If you enable extended regular expressions then the { and } characters are meta-characters and need to be escaped as well.
sed -r 's/\{\\\{\}\}//g' file >modified-file
For regular sed, only the backslash is a meta-character, and needs to be escaped.
sed 's/{\\{}}//g' file >modified-file
If you enable extended regular expressions then the { and } characters are meta-characters and need to be escaped as well.
sed -r 's/\{\\\{\}\}//g' file >modified-file
I still do not understand something about these regular expressions
with meta-characters.
In the context of sed "\" has a special meaning and therefor must be escaped (with "\"--which makes it a bit confusing.) to be taken literally.
In context, however, "{" or "}" do not have special meaning and therefor do not need to be escaped. If you turn on extended Regexes, then they DO need to be escaped....
To replace "\text\" with text:
sed 's_\\text\\_text_g'**
To replace "{eps}" with "eps":
sed 's_{eps}_eps_g'
OR: sed -r 's_\{eps\}_eps_g'
Any character which has a special meaning--in the context in which it used--must be escaped if it is to be taken literally.
In some cases, escaping is used to give special meaning when the character would other wise be taken literally.
Escaping an escape means that it is no longer an escape--thus you cannot use another escape to nullify the first escape. e.g. "\\\x" means literal "\", followed by an escaped "x". "\\\\" means 2 literal "\"s
say the above 5 times fast.....
**Remember that the first character after s is always the delimiter. Use any character you want to make it readable and to avoid ambiguity.
Last edited by pixellany; 12-01-2007 at 09:53 AM.
Reason: fixed boo-boo (-e should be -r)
In the context of sed "\" has a special meaning and therefor must be escaped (with "\"--which makes it a bit confusing.) to be taken literally.
In context, however, "{" or "}" do not have special meaning and therefor do not need to be escaped. If you turn on extended Regexes, then they DO need to be escaped....
To replace "\text\" with text:
sed 's_\\text\\_text_g'**
To replace "{eps}" with "eps":
sed 's_{eps}_eps_g'
OR: sed -e 's_\{eps\}_eps_g'
Any character which has a special meaning--in the context in which it used--must be escaped if it is to be taken literally.
In some cases, escaping is used to give special meaning when the character would other wise be taken literally.
Escaping an escape means that it is no longer an escape--thus you cannot use another escape to nullify the first escape. e.g. "\\\x" means literal "\", followed by an escaped "x". "\\\\" means 2 literal "\"s
say the above 5 times fast.....
**Remember that the first character after s is always the delimiter. Use any character you want to make it readable and to avoid ambiguity.
Yes, I knew that, but I still do not understand what to do
if \ and { are next to each other in the pattern.
You may have misunderstood me.
I know how to replace {eps} with eps,
but to replace \{eps\} with eps is a different story
now I have both "\" and "{" next to each other and the first
makes it difficult to escape the second
... It is interesting that it did not work
with / and : separators, it works with _ only.
It worked for me using single quotes (and correcting the syntax):
Quote:
There are three quoting mechanisms: the escape character, single
quotes, and double quotes.
A non-quoted backslash (\) is the escape character. It preserves the
literal value of the next character that follows, with the exception of
<newline>. If a \<newline> pair appears, and the backslash is not
itself quoted, the \<newline> is treated as a line continuation (that
is, it is removed from the input stream and effectively ignored).
Enclosing characters in single quotes preserves the literal value of
each character within the quotes. A single quote may not occur between
single quotes, even when preceded by a backslash.
Enclosing characters in double quotes preserves the literal value of
all characters within the quotes, with the exception of $, `, and \.
The characters $ and ` retain their special meaning within double
quotes. The backslash retains its special meaning only when followed
by one of the following characters: $, `, ", \, or <newline>. A double
quote may be quoted within double quotes by preceding it with a
backslash.
I hope you don't make a habit of using a backslash for a delimiter. It is the character used to escape other characters. You are confusing yourself with a contrived example.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.