Search and insert multi-line pattern in text file?
Posted: 24 Sep 2019 09:56
Assume I have 3 text files:
1st file "searchpattern.txt" which contains one or multiple text lines with a text pattern to search
2nd file "insertpattern.txt" which contains one or multiple text lines with a text pattern to insert
3rd file "targetfile.txt" which may contain the searchpattern and where the insert pattern should be inserted.
The task is now to search for the searchpattern inside the targetfile and to insert insertpattern immediately after the searchpattern.
If searchpattern is not found nothing should be inserted
How can I achieve this conveniently with a DOS batch script?
If necessary a 3rd party cmdline tool is acceptable.
Thank you
Peter
1st file "searchpattern.txt" which contains one or multiple text lines with a text pattern to search
2nd file "insertpattern.txt" which contains one or multiple text lines with a text pattern to insert
3rd file "targetfile.txt" which may contain the searchpattern and where the insert pattern should be inserted.
The task is now to search for the searchpattern inside the targetfile and to insert insertpattern immediately after the searchpattern.
If searchpattern is not found nothing should be inserted
How can I achieve this conveniently with a DOS batch script?
If necessary a 3rd party cmdline tool is acceptable.
Thank you
Peter