I have a bunch of files with 18 lines of text as header. I wish to comment those lines, which I normally do with the regular expression replacer searching ^ and replacing by # on the selected 18 lines.
I must do the very same on all files (sometimes more than 50), so it would be very useful to be able to do the "replace in all documents" only between rows 1 to 18 for example, or replace only in text lines.
I've tried also the macro recording, but in any case I must select the desired lines.
Thanks!
Related
Have files beginning with 15 lines of needed info, followed by 3280 extra lines of unneeded data.
Have tried multiple regex patterns to remove last 3280 lines in all files in directory.
Tried similar to:
^.*(?:\R.*){3279}\z
Fails every time when trying to replace with "" (empty) in directory of files.
Using Notepad++ Find in Files option.
How can I remove the last n number of lines from every file in the directory?
You can use
Find What: \A(.*(?:\R.*){14})(?s:.*)
Replace With: $1
Details:
\A - start of string (^ would do, too, here)
(.*(?:\R.*){14}) - fifteen lines
(?s:.*) - any text till end of the file (text).
The replacement is the backreference to Group 1 value.
Settings:
I have a bunch of files that are saved in a .pg format. I can open and edit them using notepad++.
I want to prepend in every file the same header. Is there a regular expression that could select all text in a file so that I could search and replace to add my header?
So that
Some text in file 1
Some text in file 2
...
becomes
becomes
Header
Some text in file 1
Header
Some text in file 2
...
I think this should work,
Regex:
(?s)^
Replacement string:
Header\n
Find:
(.*)^
Replace:
THIS IS THE FOOTER
Be sure you check the . matches newline box in the Search Mode box (as well as selecting Regular expression).
You can use this search/replace:
search: ^
replace: Header\n
I need to edit a large EDI message, which basically is a textfile of thousands of short lines. The reason is that it must comply to the standard specification and doesn't because in some of the segments there are an extra QTY+220 line that must be removed. It is in those segments that has 4 QTY lines where QTY+220 must be deleted. Here is a correct segment:
SEQ++79'
MOA+9:1.87945:NOK'
QTY+58:0'
QTY+136:5'
QTY+260:5'
Here is an incorrect segment:
SEQ++365'
MOA+9:1.31896:NOK'
QTY+58:0'
QTY+136:4'
QTY+220:0' <---- this line must be removed
QTY+260:4'
The complete textfile is about 75.000 lines and there are more than 2200 of these validation errors in the xml schema. I tried to make a seach and replace with notepad++ and regular expressions, but I can't make it match over multiple lines. Here is a single line:
^QTY.*'
But I want it to find matches of 4 QTY-lines and remove the 3rd line. How can I do that?
Use \n to match linebreaks.
In your example, replace
(QTY[^\n]+)\n(QTY[^\n]+)\n(QTY[^\n]+)\n(QTY[^\n]+)
with
$1\n$2\n$4
to remove the third line
Problem - Multiline, Semi-colon delimited file has been split at column 79 or 80 (not always the same for some strange reason).
It seems to me that a Regex would be the appropriate solution, so now I have two problems.
Lines are:
1sdf.............................mno[cr][lf]
pqr........xyz......................[cr][lf]
.....|.....|.....|.....|.....|.....|[cr][lf]
2sdf.............................mno[cr][lf]
pqr........xyz......................[cr][lf]
.....|.....|.....|.....|.....|.....|[cr][lf]
3sdf.............................mno[cr][lf]
pqr........xyz......................[cr][lf]
.....|.....|.....|.....|.....|.....|[cr][lf]
4sdf.............................mno[cr][lf]
pqr........xyz......................[cr][lf]
.....|.....|.....|.....|.....|.....|[cr][lf]
... 10000 rows ...
Where the pipe is a non-space whitespace character (possibly a tab)
I need:
1sdf.............................mnopqr........xyz......................[cr][lf]
2sdf.............................mnopqr........xyz......................[cr][lf]
3sdf.............................mnopqr........xyz......................[cr][lf]
4sdf.............................mnopqr........xyz......................[cr][lf]
I managed to get the job done with
Pass 1:
Replace ^\s*\r\n with \rxxx\n
// Replace Blank lines with \rxxx\n leaving
1sdf.............................mno[cr][lf]
pqr........xyz......................[cr][lf]
[cr]xxx[lf]
2sdf.............................mno[cr][lf]
pqr........xyz......................[cr][lf]
Pass 2:
Replace \r\n with [empty]
//leaving:
1sdf.............................mnopqr........xyz......................[cr]
xxx[lf]
2sdf.............................mnopqr........xyz......................
Pass 3:
Replace \rxxx\n with \r\n
//leaving:
1sdf.............................mnopqr........xyz......................[cr][lf]
2sdf.............................mnopqr........xyz......................
And the rest of the cleanup is trivial.
Is there any way of doing this in a single step? The output is from a common financial application, and I'd rather be able to fix the files myself rather than try and get many multiple clients to adjust their output.
In Notepad++ (using regular expression mode) you can use this:
Find what: \r\n(\s*\r\n)?
Replace with: \1
Then run "Replace All" exactly once. However, make sure you update to Notepad++ 6! Otherwise matching \r\n with a regular expression won't work in Notepad++.
Assuming that ^\s*\r\n match the line you want to remove as you said above, I believe you could do it with replacing \r\n\s*\r\n|\r\n by \r\n
It's my first regex, so if it doesn't work, don't be to harsh :-)
Good luck
I find Notepad++ regex to be very different from regex in Microsoft Word. I was wondering how I can group several lines of text using Notepad++. I have a text file with 100+ URLs. They are written one URL address per line. I would like to group all of them by tens by removing the carriage returns from every first to 9th line, but retaining the carriage return on every 10th line and adding another carriage return thereafter. For example:
I want this:
http://website1.com
http://website2.com
http://website3.com
http://website4.com
http://website5.com
http://website6.com
http://website7.com
http://website8.com
http://website9.com
http://website10.com
http://website11.com
http://website12.com
http://website13.com
http://website14.com
http://website15.com
http://website16.com
http://website17.com
http://website18.com
http://website19.com
http://website20.com
http://website21.com
http://website22.com
http://website23.com
http://website24.com
http://website25.com
http://website26.com
http://website27.com
http://website28.com
http://website29.com
http://website30.com
to look like:
http://website1.comhttp://website2.comhttp://website3.comhttp://website4.comhttp://website5.comhttp://website6.comhttp://website7.comhttp://website8.comhttp://website9.comhttp://website10.com
http://website11.comhttp://website12.comhttp://website13.comhttp://website14.comhttp://website15.comhttp://website16.comhttp://website17.comhttp://website18.comhttp://website19.comhttp://website20.com
http://website21.comhttp://website22.comhttp://website23.comhttp://website24.comhttp://website25.comhttp://website26.comhttp://website27.comhttp://website28.comhttp://website29.comhttp://website30.com
Any help would be appreciated!
Ok, I have found a way:
There is a such possibility, but only with 6 entries in a row (longest regex is not parsed by the Notepad++).
1)So, open the file and remove from it all newlines characters, so the text will be a long-long line.
2)Open replace dialog, insert in the "Find what" field the next :
(http://[^\:]*\.comhttp://[^\:]*\.comhttp://[^\:]*\.comhttp://[^\:]*\.comhttp://[^\:]*\.comhttp://[^\:]*\.com)
and in the "Replace With" the next:
\1\r\n
Put the cursor at the first position in the text and press "Replace all"
So, the regex contains this (http://[^\:]*\.com){6} (the regex is repeated 6 times). If you work with Unix and you need unix-type new line style, replace this : \1\r\n with this \1\n