Friday, May 27, 2011

Multiple Lines to a Single Line using Powershell

#declare a variable to dump a text file into
$a

#Pipe the file into the variable using the cmdlet tee-object and pump the unwanted output to (dev) null
cat temp.txt | tee-object -Variable a > $null

#Place the value into a string
[string]$strA = $a

#Print your string or store it to another file, either way it is now
#all on one line with a single CRLF at the end of the line
#print to screen

$strA 

#output to file
$strA > onOneLine.txt


Update: Added the PowerShell brush for syntax highlighting

No comments:

Post a Comment