June 14th, 2015

PowerTip: Use PowerShell to Parse Delimiters in File

Doctor Scripto
Scripter

Summary: Use Windows PowerShell to parse file delimiters in a file. Hey, Scripting Guy! Question How can I use Windows PowerShell to break out lines in a text file that are delimited by “\”? Here is the file content:

PS C:> Get-Content C:fsoAnEmptyFile.txt

This is content

\mydata\more stuff

\addmydata\addmore stuff\evenmore

Hey, Scripting Guy! Answer Use the –Delimiter parameter of the Get-Content cmdlet. Here is an example with the associated output:

PS C:> Get-Content C:fsoAnEmptyFile.txt -Delimiter \

This is content

\

mydata\

more stuff

\

addmydata\

addmore stuff\

evenmore

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.