Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Search for and replace line of text

$
0
0

Hello,

I need a powershell script to search a text file for a known line of text ('Line 2 Heading'), delete the following line, replace it with another line and save contents to a new file name.

The line to replace starts with a 'tab'. The line to insert must start with a 'tab' also.

Sample text file contents

Line 1 Heading

       Line 1 text

Line 2 Heading

       Line 2 text

Line 3 Heading

       Line 3 text

Required text file contents

Line 1 Heading

       Line 1 text

Line 2 Heading

       New text goes here

Line 3 Heading

       Line 3 text

Hope this is clear.

Any help appreciated.

Thanks,

Mike


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>