user2958941
user2958941

Reputation: 1

How to format text file and export as html in Powershell?

How can I import a text file and use regex to format the text file then export it in HTML?

Upvotes: 0

Views: 4390

Answers (1)

Keith Hill
Keith Hill

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

Related Questions