Reputation: 1
How can I import a text file and use regex to format the text file then export it in HTML?
Upvotes: 0
Views: 4390
Reputation: 201872
To read a text file use Get-Content file.txt
. To massage the text using regex I would use the -replace
operator. Then just redirect the output to an html file e.g.:
$header = "<html><head>...</head><body>"
$body = Get-Content file.txt | Foreach {$_ -replace '^(.*)$','<p>$1</p>'}
$footer = "</body></html>"
$header + $body + $footer > file.html
Upvotes: 2