Reputation: 1318
I am trying to write a PowerShell script that does the following:
Open a text file.
Find a line that matches the following pattern:
public interface $A extends InterfaceName
and change it to:
public interface $A extends InterfaceName<$A>
Save the file.
Upvotes: 0
Views: 304
Reputation: 24916
You can read the data from a file using Get-Content
, search for the match and replace it using Foreach-Object
and -replace
, and then write it back to the file using Set-Content
. The regular expression can be used to add the code that you need:
# Get the content from a file
Get-Content 'C:\path_to_your_file.txt' |
# Get replace each line if it matches the pattern
ForEach-Object {$_ -replace "(public interface (\S+) extends InterfaceName)", ' $1<$2>' } |
# Save the changes back to the file
Set-Content 'C:\path_to_your_file.txt'
Upvotes: 2