powershell - change line in file -
i trying write powershell script following:
open text file.
find line matches following pattern:
public interface $a extends interfacename
and change to:
public interface $a extends interfacename<$a>
save file.
you can read data file using get-content
, search match , replace using foreach-object
, -replace
, , write file using set-content
. regular expression can used add code need:
# content file get-content 'c:\path_to_your_file.txt' | # replace each line if matches pattern foreach-object {$_ -replace "(public interface (\s+) extends interfacename)", ' $1<$2>' } | # save changes file set-content 'c:\path_to_your_file.txt'
Comments
Post a Comment