Answer the question
In order to leave comments, you need to log in
How to perform character escaping in regular expressions?
Hey Habr!
There is Linux
There is a file.
In it, you need to replace the line "text1/text2 text3/text4"
with "text5"
.
Google suggested that the issue is solved with the help of
"sed '/s/старое/новое/g' file.txt > file2.txt"
.
But if the "old" contains the "/" character, we get
sed: -e выражение #1, символ 10: неизвестный модификатор к `s'
.
If it contains a space, then
sed: -e выражение #1, символ 6: незавершенная команда `s'
Escaping with "\" did not help. Help out who can.
UPD. Checked worked: "sed s%с/тар\ ое%новое%g file.txt > file2.txt"
.
It turns out that the character "\" successfully escapes the space, but it does not cope with "/", so "/" was replaced by "%". Unfortunately, in this case, "%" is no longer escaped. But nothing prevents you from executing 2 commands, one will have "/", the other "%".
Thank you all for your help.
Answer the question
In order to leave comments, you need to log in
All this is strange . Of
course, your sh has its own escaping features, but it should work.
[[email protected] ~]$ echo 'some/another here' | sed -e 's/some\/another here/more/'
more
Use to your health:
perl -pi -e 's/text1\/text2\ text3\/text4/text5/g'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question