A
A
Alexander Urich2014-11-14 12:32:30
linux
Alexander Urich, 2014-11-14 12:32:30

How to replace text in a file using sed and a regular expression?

You need to replace the text in the file according to the regular expression. In PHP it works without problems.
The task is this:
Find the text by the expression
#\[0-9]+\<\/maxplayers\>#
And replace the numbers in it.
For example
55
Replace with
128
I write like this:
sed -i 's#\[0-9]+\<\/maxplayers\>#55#g' /path/to/file
Judging by the file update time, it writes something . But no change...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vladimir, 2014-11-14
@Urichalex

sed -i '/<\/maxplayers>/{s/55/128/g}' /path/to/file

S
seniorivn, 2014-11-14
@seniorivn

test on a single line file.

S
Sergey Petrikov, 2014-11-14
@RicoX

# change to /

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question