![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Reading a text file and retaining line feeds I've tried reading a text file using $reportContent = get-content -path $tempFilePath but it loses the line-feeds so I just get one long string. Can I do it with get-content or do I need to use a StreamReader or something similar? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Reading a text file and retaining line feeds The get-content cmdlet does remove line-feeds, but it actually reads each line into a string object, and stores each line in an array. From the help: Quote: >get-help get-content DETAILED DESCRIPTION It reads the content one line at a time and returns an object for each line. #Example: Quote: >get-content -path test1.txt|write-host Line2 Quote: >$a = get-content -path test1.txt >$a.Length Quote: >$a[0] Quote: >$a[1] Quote: >set-content -path test2.txt $a >get-content -path test2.txt|write-host Line2 Quote: >get-content -path test2.txt|write-host -noNewLine Most Windows text files end lines with 2 characters, the carriage-return + line-feed (\r\n or Chr13 + Chr10). Maybe there's something different about your original text, maybe it comes from Unix/Linux or Mac, and it only contains a line-feed or carriage-return but not both? "ssg31415926" <newsjunkmail@xxxxxx> wrote in message news:8c837cc7-dfb8-425f-8eaa-102c731922d2@xxxxxx Quote: > I've tried reading a text file using > > $reportContent = get-content -path $tempFilePath > > but it loses the line-feeds so I just get one long string. Can I do > it with get-content or do I need to use a StreamReader or something > similar? |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Reading A Text File | VB Script | |||
| Reading text file at a URL | VB Script | |||
| reading last line of file | VB Script | |||
| Reading a text file with StreamReader | .NET General | |||
| reading a big file line by line to be "out of memory" safe | PowerShell | |||