K
K
Kirows2015-07-11 14:38:52
cmd/bat
Kirows, 2015-07-11 14:38:52

How to remove lines of a certain length from a txt file?

There are several files with 100+k lines.
How to remove lines containing 4 or less characters from a text file.
I found functions separately, I am not able to splice the brain.
search string tyts
delete string tyts

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MK, 2015-07-11
@Kirows

I had to puff, but stubbornness took over =)
here is the code:

@echo off
goto :main
:choosestr
set string=%~1
set strstart=%string:~0,4%
set strend=%string:~-4%
if NOT %strstart%==%strend% echo %string%>>1.txt
goto :EOF
:main
set tpath=%tmp%/%RANDOM%%RANDOM%.tmp
type 1.txt>%tpath%
type nul>1.txt
FOR /F %%i in (%tpath%) do call :choosestr %%i

Wherever 1.txt is replaced with your
PS file, if necessary, I can comment

E
Eugene, 2015-07-12
@yellowmew

One line in Powershell
You can also add Move-Item d:\outfile.txt d:\file.txt -force
if the old data is not important.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question