A
A
akv2016-04-13 10:13:35
HTML
akv, 2016-04-13 10:13:35

Enums in notepad++?

Good day everyone! There was a question, there are a bunch of lines like:

add name="pnachmed" target=192.168.0.121 max-limit=5M/5M
add name="mam1" target=192.168.0.122 max-limit=5M/5M
add name="hz-comp3" target=192.168.0.123 max-limit=5M/5M
add name="zavhoz" target=192.168.0.124 max-limit=5M/5M

You need to replace it with an enumeration and bring it to this form:
add name="1" target=192.168.0.121 max-limit=5M/5M
add name="2" target=192.168.0.122 max-limit=5M/5M
add name="3" target=192.168.0.123 max-limit=5M/5M
add name="4" target=192.168.0.124 max-limit=5M/5M
and so on...
Is it possible to do this via find replace?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2016-04-13
@akv

Nothing in notepad++, but easy in PHP:

$data = explode(PHP_EOL, file_get_contents('data.txt') );

foreach($data as $id => $value){
  $data[$id] = preg_replace('/name\=\"([^\"]*)\"/ui', 'name="' . ($id+1) . '"', $value);
}

file_put_contents('new_data.txt', implode(PHP_EOL,$data) );

K
khipster, 2016-04-13
@khipster

Easy, you can also use regular expressions there. But you didn't explain in the question what to change to what. If it's just the name attribute, then you can do it without the regular expression.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question