Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of the sorted file is double than original file in powershell

I have a powershell script, that reads file content, sorts it and writes output to new file. Following is the script:

get-content $inputFile | sort > $sortedFile

The output in file is sorted properly, but the output file ($sortedFile) is double larger than input file ($inputFile). Note: There are no duplicate or extra line in output file.

Any help or ideas regarding this will be helpful.

like image 831
Yauvaraj Rimal Avatar asked Jan 27 '14 06:01

Yauvaraj Rimal


1 Answers

Most likely the input file is ascii encoding while the default output using redirection is unicode encoding.

Instead of using > as redirection you can use out-file and specify an encoding.

get-content $inputFile | sort | out-file -encoding ASCII

like image 78
Lieven Keersmaekers Avatar answered Nov 01 '22 22:11

Lieven Keersmaekers