Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

367.Replace text in multiple files -- How can I replace the 3rd lines of many files to a fixed string?

User: editor -- 2009-12-15          << 366  368 >>
Hits: 409
Type: Replace text in multiple files   
Search all Replace text in multiple files examples
Description:
I have hundreds of files that in different folders with same name fff.txt, in these files, the text in the 3rd lines are different:

the 3rd line in 1st file: <id>33</id>
the 3rd line in 2nd file: <id>25</id>
...

How can I replace the 3rd lines of all these files to <id>1</id>?
Input Sample:
line1
line2
<id>xxx</id>
line4
Output Sample:
line1
line2
<id>1</id>
line4
Answer:
Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps.
Firstly, search the files:
1. Press ctrl-B open "Batch Runner" dialog
2. Click "Search Files" button
* Fill In Filename filter: fff.txt
* Select search Directory to parent folder of all files
* Check Search subdirectory option
* Click 'Search' to search all files, and click "Close" to close search window

Now all files are listed, secondly, make replacement:
3. Click "Fast Replace" to open "Fast Replace" window
4. Click "add", 
* fill in Search like:

* fill in Replace like:

* click 'OK'
5. click 'Start'

Note: 
^((.*?\n){2})[^\n]* is regular expression, matches the first 3 lines.
((.*?\n){2}) matches the first 2 lines, 

Screenshot 1:  Fast_Replace_Window


Similar Examples:
How to replace the same words in text files with different strings? (64%)
How to replace strings in multiple files with a global  increasing ID? (59%)
How to replace multiple text in multiple files with variable strings? (59%)
How to delete the first 1-10 lines in many files?  (58%)
How can I remove/delete 'word1', 'word2', ... in many files in one step? (58%)
How can I search and replace multiple strings in multiple files all at once? (57%)
How to delete all lines appear in file B from file A? (57%)
How to batch replace 'old' to 'new' in many pdf files? (57%)

Check Demo of Replace text in multiple files
Keywords:
different folder  matches  same name  subdirectory  1st  2nd  folders  fixed  same  directory  add first line to all lines  replace same with different  many folders  can make multiple search and replace  replace first string  folders files  replace string in multiple files  file name filter