Deleting last line from notepad++ files - regex

I am having a small problem regarding removal of last line from text files. I have over 500 text files and in each of them the last line is simply blank. I want to find some quick method to delete these empty lines. I am looking for some search and replace method to remove these lines.
So far I have tried searching \r\n and other methods but nothing works. Only thing that works is by going to edit->line operations-> Remove Empty Lines but it is cumbersome to do this individually for each file.
So is there any way to achieve this?
Ahmar

Have a try with:
Find what: \n$
Replace with: NOTHING

Use the regular expression \r\n\Z.
Search > Find in Files. You're looking for \r\n\Z, replace with nothing, and make sure Regular Expression is checked at the bottom.

Related

Regex Find and Replace using line numbers condition in editplus

I have a huge text file with over 20K lines of content. I am using editplus 4.0 version to achieve my desired result.
What I want to do is;
I want to insert/append a keyword, randomly in the content. Now, the condition is, I want to insert my keyword once for every 60 lines.
If I achieve this, next I have another app which can split my huge content into multiple lines based on line count, which is 60 in this case.
So, end of the day I will have my content into multiple text files and every file includes my keyword which I am going to use it for blog posting.
Please suggest me if I can do this with editplus, other ways of achieving the same will also welcome.
I tried lot of options but no luck.
Thanks in advance !!
AFAIK editplus doesn't work with regex.
I suggest you to use Notepad++, with it you can do:
Ctrl+H
Find what: ((?:[^\r\n]*\R){60})
Replace with: $1KEYWORD\n
Replace all
Don't forget to select Regular expression in search mode.

Notepad ++ Find all lines containing xxxxxx/Reports/reportname.pdf and replace with xxxxxx/Reports/PDF/reportname.pdf

Screenshot of the fileI have a file which contains multiple lines
Source Path Target Path
xxxx/out/reportname1.pdf xxxx/out/Reports/reportname1.pdf
xxxx/out/reportname2.txt xxxx/out/Reports/reportname2.txt
xxxx/out/reportname3.csv xxxx/out/Reports/reportname2.csv
I would like to replace /Reports/reportname1.pdf to /PDFReports/reportname1.pdf for only PDF files.
Please suggest I tried using /Reports/.*pdf and I am able to find it, but unable to replace it
Search for \/Reports\/(.*?\.pdf) and replace with /PDFReports/$1
You would need to use replacing with regex syntax (ctrl+H by default)
Try something like:
Find what:
\/Reports\/(.*\.pdf)
Replace with:
/PDFReports/$1
And use "regular expression" search mode.
This mechanism is called capture group - braces in "Find what" are used to remember the content inside them and then this content is references later by $1.
Note - you might have to use "\1" instead of "$1" in case of old version of Np++
searching pattern: ([\w\_]+\.\w+)
replace to: Reports/$1
output:
xxxx/out/Reports/reportname1.pdf
xxxx/out/Reports/reportname2.txt
xxxx/out/Reports/reportname3.csv
EDIT: since filenames could containt _, little upgrade.

How do I join two regular expressions into one in Notepad++?

I've been searching a lot in the web and in here but I can't find a solution to this.
I have to make two replacements in all registry paths saved in a text file as follows:
replace all asterisc with: [#42]
replace all single backslashes with two.
I already have two expressions that do this right:
1st case:
Find: (\*) - Replace: \[#42\]
2nd case:
Find: ([^\\])(\\)([^\\]) - Replace: $1$2\\$3
Now, all I want is to join them together into just one expression so that I can do run this in one time only.
I'm using Notepad++ 6.5.1 in Windows 7 (64 bits).
Example line in which I want this to work (I include backslashes but i don't know if they will appear right in the html):
HKLM\SOFTWARE\Classes\*\shellex\ContextMenuHandlers\
I already tried separating it with a pipe, like I do in Jscript (WSH), but it doesn't work here. I also tried a lot of other things but none worked.
Any help?
Thanks!
Edit: I have put all the backslashes right, but the page html seem to be "eating" some of them!
Edit2: Someone reedited my text to include an accent that doesn't remove the backslashes, so the expressions went wrong again. But I got it and fixed it. ;-)
Sorry, but this was my first post here. :)
As everyone else already mentioned this is not possible.
But, you can achieve what you want in Notepad++ by using a Macro.
Go to "Macro" > "Start Recording" menu, apply those two search and replace regular expressions, press "Stop Recording", then "Save Current Recorded Macro", there give it a name, assign a shortcut, and you are done. You now can reuse the same replacements whenever you want with one shortcut.
Since your replacement strings are totally different and use data that come not from any capture (i.e. [#42]), you can't.
Keep in mind that replacement strings are only masks, and can not contain any conditional content.

Regular Expression to Remove Subdomains from Domain List

I have a list of domains and subdomains stored in a .txt file (I'm using Windows XP).
The format of the domains is this:
somesite1.com
sub1.somesite1.com
sub2.somesite1.com
somesite2.com
sub1.somesite2.com
sub2.somesite2.com
somesite3.com
sub1.somesite3.com
sub2.somesite3.com
I use notepad++, and I need to use regular expressions
Anyway, I don't know what to put in the find & replace boxes so it can go through the contents of the file and leave me with only the root domains. If done properly, it would turn the above example list into this:
somesite1.com
somesite2.com
somesite3.com
Can somebody help me out?
Thank you in advance.
It's an old question, but the answers provided didn't work for me. You need a negative lookahead. The correct regex is:
^\w*\.(?!\w+\s*\n)
You can use:
Find what: [^\r\n]+\.[^.\r\n]+\.[^.\r\n]+[\r\n]+
Replace with: empty_string
with regular expression checked and dot match line-feed NOT checked
I suggest using the Mark tab of the Notepad++ Find dialogue. Enter the regular expression ^\w+\.\w+\.\w+$, make sure that Bookmark line is selected, then click Mark all. Next, use Menu => Search => Bookmark => Remove bookmarked lines. These will remove all entries having with three "words" separated by two dots. It will leave all other lines in place.
An alternative is to mark all lines matching the regular expression ^\w+\.\w+$ and use the Remove unmarked lines menu entry. This I do not recommend as it will remove all lines with an unexpected format as well as the lines for subdomains.
Another method would use the Replace tab of the Notepad++ Find dialogue. Enter the regular expression ^\w+\.\w+\.\w+\r\n in the Find what field, and leave the Replace with field empty. The \r\n part of this expression may need some adjustment to account for the line endings set on the file.

How can I match the beginning of a line in dreamweaver with regex?

Problem:
^.+ matches only the first line of the source code in dreamweaver. I need it to match each line so that I can wrap each full line in P tags. I have 500 files to do this in.
I know ^ should match the beginning of a line and I also know that multi-line mode must be enabled for it to work on each line and not just at the beginning of the file. I also know dreamweaver uses javascript source code.
Is lack of multi-line mode the problem? Is there any way to turn it on in dreamweaver? I tried using /m at the beginning search to enable multi-line mode, but that didn't work either.
I'm open to any solution for my current problem, even if it involves a different program. However, a fix for dreamweaver is ideal, 2nd place is a way to do this in notepad++, 3rd place is a way do to this in python or something (I only know javascript, you'll have to spell it out exactly in another language).
Thank you,
robert
p.s.
I found I can "select all > right click > selection > indent" to add two spaces to the beginning of each line in dreamweaver. This allows me to find the beginning of each line with / {2,}/. I really don't want to select all > indent on all 500 files, but i'm about to start since I've already spent a few hours bludgeoning dreamweaver.
Don't use Dreamweaver for this - use Notepad++ (since you are familiar with it) at its regular expression support is superior.
If you are comfortable with a more robust scripting language (Python, Ruby, Perl, etc.) then that would be an ever better way to do it.
The way that I might do this in DW would not involve using the find-replace tool's "Regular Expression" option, but instead using just plain old matching on a CrLf.
In the Find portion, since you can't directly enter a CrLf, you'll have to copy one to your clipboard beforehand and paste it in where needed.
In the Replace portion, replace with:
</p>[CrLf]
<p>
Again, be sure to paste in a proper "[CrLf]". This will work on all but the very first and very last lines of your document, so I know this isn't a 100% solution. There are probably better solutions using other tools that someone else can recommend!
Good luck!
-Mike
I had a flash of insight right after posting. (isn't that the way of it?)
Dreamweaver can find the end of each line with \r\n so instead of trying to work forward, i should have just worked backwards.
search: (.+)(\r\n)
replace: <p>$1</p>$2
[\w\W]* matches anything, including a newline. Its greedy, so it fact it matches everything.