![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| Member | add an empty line to txt file every two rows. Hi guys. I've a txt file like this line1 line2 ... line n and so on I need to create a new file adding an empty line every two rows line1 line2 line3 line4 line5 I wrote this code: $i=0; gc myfile.txt | % {$i=$i++; if($i%2 -eq 0) {add-content newfile.txt $_} else {add-content newfile.txt `n,$_}} but the file remains the same. Where's my mistake? Thanks in advance. |
My System Specs![]() |
| | #2 (permalink) |
| Member | Re: add an empty line to txt file every two rows. I spent an hour looking for a solution. Now that I posted finally I found it. $i=1; gc myfile.txt | % {if($i%2 -ne 0) {add-content newfile.txt $_} else {add-content newfile.txt $_,`r};$i++} Thanks the same. Have a nice day! |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: add an empty line to txt file every two rows. Shorter version: # insert NL every 2 lines sc new.txt (gc old.txt | % {$l = 1} {if ($l++ % 2) {$_} else {$_,''}}) -- Kiron |
My System Specs![]() |
| | #4 (permalink) |
| Member | Re: add an empty line to txt file every two rows. Great solution Kiron! Thank you very much. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| find last non-empty line | VB Script | |||
| How do I filter rows in one csv file matching a value in another | PowerShell | |||
| file folder icons display non-empty folders as empty | Vista file management | |||
| Count the number of Columns/rows in a CSV file.... | PowerShell | |||
| Mysterious empty line in DateTime formatting | PowerShell | |||