How to Remove Empty Rows With Powershell

How to Remove Empty Rows With Powershell thumbnail
Prepare your file by removing the blank lines.

Blank lines can be problematic when you import a file from one program to another. For example, if you import a text file into Excel or Access, those blank lines will be reflected in the resulting spreadsheet or database tables. You can avoid those problems by using Powershell to remove those empty rows before you do your import.

Instructions

    • 1

      Log on to your computer and open Windows Explorer. Note the name of the file which contains the empty rows you want to remove with Powershell.

    • 2

      Open Powershell. Type the following command:

      gc c:\filename.txt | where {$_ -ne ""} > c:\newfile.txt

      This command takes the original file, removes the empty lines and writes a new file without those lines, using the file name you specified. In the above example the original file name was filename.txt and the name of the new file without the blank lines is newfile.txt.

    • 3

      Close Powershell and navigate to the new file. Verify that the blank lines have been removed.

Related Searches:
  • Photo Credit Burke/Triolo Productions/Brand X Pictures/Getty Images

Comments

Related Ads

Featured