Jump to content
way1000

delete lines containing

Recommended Posts

way1000

i have a text file with 1 million lines where i have to remove 800k lines. i want to remove the 800k lines and keep the 200k lines but the line order has to remain the same. lines removed should become empty lines so there should still be 1 million lines but only 200k with text

Share this post


Link to post
Share on other sites
spudw2k
gruntydatsun

you're going to go way over the size limit for variables in autoit with that job unless you shuffle things around as you go.  Might be less hassle to just do it in a text editor like npp or sublime with find/replace and a regex.  If this doesn't need to be automated that is.

Share this post


Link to post
Share on other sites
mikell
49 minutes ago, gruntydatsun said:

you're going to go way over the size limit for variables in autoit

It depends on the size of the lines ;)

;#cs
$txt = ""
For $i = 0 to 1500000
   $txt &= "this is the line of text #" & $i & @crlf
Next
FileWrite("1.txt", $txt)
;#ce

$txt = FileRead("1.txt")
; remove text from lines ending with 12, 14, 16
$new = StringRegExpReplace($txt, '(?m)^.*1[246]$', "")
FileWrite("new.txt", $new)

 

Share this post


Link to post
Share on other sites
way1000

here's an example of the text file before and after

option: remove lines containing "items4"

there's 200k lines to be removed in 1 million lines.the lines removed have to stay empty (like in the screenshot), it's a must

toremovelinefrom.png

linesremoved.png

Share this post


Link to post
Share on other sites
mikell

Did you try my previous code ? a little adaptation gives this (based precisely on the provided requirements) :

$txt = FileRead("1.txt")
$out = "items4"
$new = StringRegExpReplace($txt, '(?m)^.*\Q' & $out & '\E.*$', "")
FileWrite("new.txt", $new)

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×