A
A
Azat Kiberov2018-12-27 21:29:10
Windows
Azat Kiberov, 2018-12-27 21:29:10

How to quickly replace numbers in documents of the same type with different ones in only one place?

For example, there is a document with content:
Programmer's site ..Go to content on page 1.
And there are 100 such files..With the same text.
Need the following.
1.php - find the number 1, replace with 2
2.php - find the number 1, replace with 3
2.php - find the number 1, replace with 4
And so 100 times. How to do it quickly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2018-12-27
@Alex_At_Net

Try this:
1. Back up your files
2. Create an update.js file (code below) in your files directory
3. Run node update.js
update.js

const fs = require('fs');
fs.readdirSync('.')
  .filter(file => file.indexOf('.php') !== -1)
  .forEach(file =>
    fs.writeFileSync(file,
      fs.readFileSync(file, { encoding: 'utf8' })
        .replace('1', parseInt(file))));

I
Interface, 2018-12-27
@Interface

so write a node.js or php script that will go through the files and make a replacement.
- get a list of files
- read each one
- replace a substring
- write a file
each of these items is easy to google. business for 10 minutes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question