Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

How can i delete blank rows in a text file.

Hi,

I want to delete the blank rows in the text file.I dont want to put the data to any other file edit and replace it to the text file.Any built in way or a script to run on the text file to remove blank lines.

Regards
Sharath
Avatar of BSonPosh
BSonPosh
Flag of United States of America image

If you dont mind powershell

$file = "PathtoYourFileNameHere"
$data = get-content $file; $data | ?{($_)} | out-File -enc ASCII $file
Avatar of bsharath

ASKER

What filename should i save this
If you want it as a script do this. I was just expecting you do to it at the prompt

Name = Remove-Spaces.ps1
### Cut/Paste ###
$param ($file)
$data = get-content $file
$data | ?{($_)} | out-File -enc ASCII $file
###############

From the PS Prompt
PS> C:\MyPathtoScript\Remove-Spaces.ps1 c:\MyFilePath\FileName.txt

This will require Powershell be installed. I reread your requirements and I noticed you wanted this built in. Powershell does need to be installed. I can do this in batch but you will need a temp file.
Avatar of Speshalyst
Or simply export this txt file into Excel using

Data>Import External Data> Import Data> ... browse to ur txt file.. it should import ur data into rows and ..

Now go to  EDIT>Go To > Click on Special > select Blanks and click ok .. all the blank cells in a row would be selected..
now u can delete them... just hit the DEl key
SOLUTION
Avatar of BSonPosh
BSonPosh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial