Accepted Solution

output to file only in one line


Appreciate if you can help on the scenario below. In powershell window the output is formatted (line by line) but when I send it to a text file, it's only one line. How to keep it the same?

Command Output

PS C:\> Read-NaFile /vol/vol0/etc/rc

#Auto-generated by setup Wed Apr 25 10:11:51 GMT 2012

hostname FILER1

ifgrp create multi vif1 -b ip e0a e0b

ifconfig vif1 `hostname`-vif1 mediatype auto netmask

route add default 1

routed on

options dns.enable off

options nis.enable off


PS C:\> Read-NaFile /vol/vol0/etc/rc >c:\test.txt

Notepad Output (one line)

Thanks in advance!

Re: output to file only in one line


     This is an issue with Notepad and how it treats carriage feed / line return.  This particular issue is why you shouldn't use Notepad to edit config files, Notepad does not respect the conventions of the source format and changes the output.  If you edit /etc/exports with Notepad, then save, go to a Unix system and run cat -v /etc/exports you will see the "^M" character all through the file, you should see "$". I have seen this break config files many times.  Unfortunately this is common with a lot of Microsoft products.

If you use something like Wordpad(on Windows 7 at least), Notepad++, Textpad, Crimson Editor, etc they will show you the ouput in the correct format without issue.  You would have to build a wrapper script to change the Unix CR/LF to the Windows ^M to get Notepad to show the output correctly.

- Scott

output to file only in one line

Hi Scott,

Thanks for pointing out. I managed to resolve it.

$lines = gc "path to the file"

$lines | out-file "path to the file" -Encoding unicode