Delete x lines, then stop

A place to try and solve your RegEx problems.
Post Reply
rossnixon
Posts: 3
Joined: Tue Mar 17, 2015 6:00 am

Delete x lines, then stop

Post by rossnixon »

I have text files which I want to remove the first 9 lines from.
I have not been able to work out the syntax. Using Windows, so need to remove the CRLF characters also.

Alternative solution possible, as line 10 always begins with the word "Region" (without quotes),
so a solution which removes everything prior to this text would also be suitable.

Thanks for any answers!
User avatar
DigitalVolcano
Site Admin
Posts: 1715
Joined: Thu Jun 09, 2011 10:04 am

Re: Delete x lines, then stop

Post by DigitalVolcano »

You can try

Regex:

Code: Select all

.*?(region)
Replace:
$1

With 'dot maches newline' checked.

This should work if you don't have later lines with 'region' in the file, otherwise you may lose more data. Always test and back up first!
me_suzy
Posts: 20
Joined: Thu Jul 14, 2016 11:31 am

Re: Delete x lines, then stop

Post by me_suzy »

see https://forum.sublimetext.com/t/regex-m ... mpty/20850

This will delete the first 10 lines.

(\s*^(\h*\S.*)){10}
rossnixon
Posts: 3
Joined: Tue Mar 17, 2015 6:00 am

Re: Delete x lines, then stop

Post by rossnixon »

Thanks Suzy.
In the end I went with a compiled AutoIt script to process all the files in a folder.
me_suzy
Posts: 20
Joined: Thu Jul 14, 2016 11:31 am

Re: Delete x lines, then stop

Post by me_suzy »

it is good this Autoit software?
rossnixon
Posts: 3
Joined: Tue Mar 17, 2015 6:00 am

Re: Delete x lines, then stop

Post by rossnixon »

It is good for me. I use it to automate several tasks in my job. It isn't a full programming language though.

AutoIt is typically used to produce utility software for Windows and to automate routine tasks, such as systems management, monitoring, maintenance, or software installation. It is also used to simulate user interaction, whereby an application is "driven" (via automated form entry, keypresses, mouse clicks, and so on).
https://en.wikipedia.org/wiki/AutoIt
Post Reply