Deleting last line in files

General discussions about Advanced Find and Replace
Post Reply
frankm
Posts: 3
Joined: Fri Mar 02, 2007 1:10 am

Deleting last line in files

Post by frankm »

I'm sure this is easy but I can't figure out how to do it.

I want to use AFR to delete the last line of a few thousand text files but I don't know what regular expression to use to select the last line - the last lines don't necessarily end with line breaks.

Thanks

Abacre
Site Admin
Posts: 1223
Joined: Mon Jan 31, 2005 5:32 pm

Re: Deleting last line in files

Post by Abacre »

Go to main menu - Action - Options - Batch Replace
check "Modifier S"
check "Modifier G"

Go to Batch replace tab, check on "Use regular expressions".
Put into the grid, search for:
\A(.*)\r\n.*\r?\n?\Z

Replace with:
$1

That's all I verified it works perfectly.

Note: in this example we use line breaks used in Windows (\r\n)
Otherwise you should use search for: \A(.*)\n.*\n?\Z
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

frankm
Posts: 3
Joined: Fri Mar 02, 2007 1:10 am

Re: Deleting last line in files

Post by frankm »

Thank you Roman - that works great. :D

digitalmonkeyman
Posts: 4
Joined: Sun Sep 16, 2007 7:35 am

Re: Deleting last line in files

Post by digitalmonkeyman »

solution received


Thanks

Post Reply