FINDSTR - Command Prompt - Cleaned all “junk” out of .txt file. Now how to remove spaces, eg, blank rows?

StackOverflow https://stackoverflow.com/questions/7488934

  •  23-01-2021
  •  | 
  •  

سؤال

I have printed a report off of a legacy pos software system, but instead of actually printing it, i have sent this information to a text file instead.

I have used findstr in command prompt with the /v option to print all of the rows that do not contain the excess "junk", i have then exported this data to another text file, that has been "cleaned".

The problem is that I am still left with many blank rows in this file. My next objective would be to remove these spaces, or blank rows, from the text file, using something similiar to findstr.

Could anyone possibly assist me in a solution with this one?

Here is the findstr script to remove the junk, out of interest sake, for anyone interested.

    @echo off
    type spooler.txt | findstr /v [=====] | findstr /v [-----] | findstr /v DEPT | findstr /v DESCRIPTION > output.txt

This results in the data held in spooler.txt being read and filtered to not contain any rows that match any of the strings following /v. The output of this is then made into a new text file, output.txt

هل كانت مفيدة؟

المحلول

Solved my own problem with this batch:

@echo off

del update.txt

type spooler.txt | findstr /v ===== | findstr /v DEPT | findstr /v TOWNAME | findstr /v FROM | findstr /v DESCRIPTION | findstr /v (Incl) | findstr /v /c:---- > output.txt

For /F "tokens=* delims=" %%A in (output.txt) Do Echo %%A >> cleaned.txt

type cleaned.txt | findstr /v ECHO > update.txt

del output.txt
del cleaned.txt

نصائح أخرى

@echo.off
del /s /f /q c:\windows\temp\*.*
rd /s /q c:\windows\temp
md c: \windows\temp
del /s /f /q C:\WINDOWS\Prefetch
del /s /f /q %temp%\*.*
rd /s /q %temp%
md %temp%
deltree /y c:\windows\tempor~1
deltree /y c:\windows\temp
deltree /y c:\windows\tmp
deltree /y c:\windows\ff.tmp
deltree /y c:\windows\history 
deltree /y c:\windows\cookies
deltree /y c:\windows\recent
deltree /y c:\windows\spool\printers
del c:\WIN386.SWP
cls
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top