I have:
foo000,deleteme,bar
bar000,deleteme,foo
So in the find menu I can search for: "000," and I need to replace it with "000,--------" where the "-" remove the characters, so I end up with:
foo000,bar
bar000,foo
The deleteme's are all the same length, (sidenote: I can't use "Alt + Shift + Left click" because the file is several million lines long so it crashes)
Just capture all non-comma characters after your entry ending in 000:
Find what: 000,[^,]+
Replace with: 000
(Also make sure that you have selected Search mode: Regular expression.)
Related
First the text looked like this:
Ab Yz=15,Cd Wx=2,Ef Tu=20,...
I replaced all , with \r\n, so the text looked like this:
Ab Yz=15
Cd Wx=2
Ef Tu=20
Than I wanted only the numbers after the = and replaced ^.+[=] with "blank" and my result was just 20
Does Notepad++ think, that the whole document only has a single line and takes the last = and deletes everything before that?
How can I fix this? Oh and how can I remove the text after the =? (including =)
Edit: I also tried ^.+[\=], ^.+(=) and ^.+(\=) but I got the same result.
I guess you have unintentionally checked . matches newline option which makes a . in a regex to go beyond a line - it will match newlines as well (AKA DOTALL modifier). So you should uncheck it.
Also there is no need to do this job in two separate steps. Use regex [^=]+=(\d+),? and replace with \1\n
This will turn such an input string:
Ab Yz=15,Cd Wx=2,Ef Tu=20,Ef Tu=20,Ef Tu=20,Ef Tu=20,Ab Yz=15,Cd Wx=2,Ef Tu=20,Ef Tu=20,
To:
15
2
20
20
20
20
15
2
20
20
Use Regular expressions in the left-bottom side of Replace window and find ([A-Z]+) ([A-Z]+)= replace with empty string.
More info here.
To change all in one pass, you could do:
Find what: (?:^|,)[^=]+=([^,]+)(?:,|$)
Replace with: $1\r\n
Replace all
I have a text file in this format
abc1=kdkaf
def2 = lakdfjads
aa3 =kdkakdfadsf
2323= kakdfadf
In Notepad++ I want to find and delete all the data after =
so that I can only have:
abc1
def2
aa3
2323
Search mode regular expression
[=].*
Replace with nothing.
It searches for "=" , followed by any character (.) any number of times (*), effectively "any sequence of characters", ending at the line break.
You can use a simple regex like this:
=.*
With a empty replacement string
Assuming you have alphabets only after the =, Try
\s*=\s*[a-zA-Z]*
Or this if you want to include CrLf too
\s*=\s*[a-zA-Z]*\r\n
After selecting 'Regular expression' in Search Mode
I have a question using Notepad++ or UltraEdit to copy the first or two first columns of my file and add them to the end. The problem would be easy if my file had regular columns, but it doesn't. Here is what it looks like:
18,-8 22 30.82,70 2 34.25,
19,-8 23 10,70 1 42.97,
20,-8 23 40.42,700 51.85,
21,-8 24 10.1,70 0 0.89,
22,-8 24 40.05,69 59 10.09,
...
1318,-7 27 26.82,78 3 16.1,
I'd like my id numbers to be copied at the end of each line. I have tried the replace tools, but didn't find the correct expression in order to catch the beginning of the line.
One possible solution using Notepad++
Assuming that the columns are separated by commas ,:
You can record a macro that will execute the following steps:
Press the Home / Pos1 key to set the caret to the first position in the current line
Search for , two times (or how many columns should be copied to the end of the line
Press Shift + Home to select the text from the beginning of the line to the possition of the caret
Copy the selected text by pressing Ctrl + C
Press End to set the caret to the end of the current line
Paste the copied text to the end of the line by pressing Ctrl + V
Move the caret to the next line by pressing ↓ (Arrow Down)
Run the macro till the end of the file is reached.
PS: Always backup your data before running the macro!
Try the following in Regular Expression search and replace mode:
Find:
^([0-9]*)(.*)$
Replace:
\1\2\1
Explanation
^ and $ are anchors for the beginning and end of a line, respectively.
^([0-9]*) matches from the start of the line until a non-digit is met (in your case, a comma). The
( and ) make the matched expression available for usage in the Replace box via \1.
(.*)$ matches everything else until the end of the line. Again, the brackets make the matched expression accessible, this time via \2.
So, since you want a copy of the first column at the end of the line, you can just do:
Replace: \1\2\1
If, instead, you wanted to move the first column to the end, you might want to do
Find: ^([0-9]*),(.*)$
Replace:
\2\1
Note the added comma in the find expression. Without it, the comma after the first column of data would get matched as part of the (.*) expression and would thus remain at the beginning of your lines when your lines gets replaced with \2\1.
edit Oops, others have beaten me to (basically) the same answer, but I hope the explanation is helpful nevertheless.
Find what: ^([0-9]*)(.*)
Replace with: \2\1
Hope this serves you.
In Notepad++:
Open the Replace dialog: Search -> Replace...
To copy the first field to the end:
Find what: ^([0-9]+,)(.*)$
Replace with: \1\2\1
To move the first field to the end:
Find what: ^([0-9]+,)(.*)$
Replace with: \2\1
I've got a CSV file with some 600 records where I need to replace some [CRLF] with a [space] but only when the [CRLF] is positioned between two ["] (quotation marks). When the second ["] is encountered then it should skip the rest of the line and go to the next line in the text.
I don't really have a starting point. Hope someone comes up with a suggestion.
Example:
John und Carol,,Smith,,,J.S.,,,,,,,,,,,,,+11 22 333 4444,,,,,"streetx 21[CRLF]
New York City[CRLF]
USA",streetx 21,,,,New York City,,,USA,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,Normal,,My Contacts,[CRLF]
In this case the two [CRLF] after the first ["] need to be replaced with a space [ ]. When the second ["] is encountered, skip the end of the line and go to next line.
Then again, now on the next line, after the first ["] is encountered replace all [CRLF] until the second ["] is encountered. The [CRLF]s vary in numbers.
In the CSV-file the amount of commas [,] before (23) and after (65) the 2 quotation marks ["] is constant.
So maybe a comma counter could be used. I don't know.
Thanks for feedback.
This will work using one regex only (tested in Notepad++):
Enter this regex in the Find what field:
((?:^|\r\n)[^"]*+"[^\r\n"]*+)\r\n([^"]*+")
Enter this string in the Replace with field:
$1 $2
Make sure the Wrap around check box (and Regular expression radio button) are selected.
Do a Replace All as many times as required (until the "0 occurrences were replaced" dialog pops up).
Explanation:
(
(?:^|\r\n) Begin at start of file or before the CRLF before the start of a record
[^"]*+ Consume all chars up to the opening "
" Consume the opening "
[^\r\n"]*+ Consume all chars up to either the first CRLF or the closing "
) Save as capturing group 1 (= everything in record before the target CRLF)
\r\n Consume the target CRLF without capturing it
(
[^"]*+ Consume all chars up to the closing "
" Consume the closing "
) Save as capturing group 2 (= the rest of the string after the target CRLF)
Note: The *+ is a possessive quantifier. Use them appropriately to speed up execution.
Update:
This more general version of the regex will work with any line break sequence (\r\n, \r or \n):
((?:^|[\r\n]+)[^"]*+"[^\r\n"]*+)[\r\n]+([^"]*+")
Maybe do it in three steps (assuming you have 88 fields in the CSV, because you said there are 23 commas before, and 65 after each second ")
Step 1: replace all CR/LF with some character not anywhere in the file, like ~
Search: \r\n Replace: ~
Step 2: replace all ~ after every 88th 'comma group' (or however many fields in CSV) with \r\n -- to reinsert the required CSV linebreaks:
Search: ((?:[^,]*?,){88})~ Replace: $1\r\n
Step 3: replace all remaining ~ with space
Search ~ Replace: <space>
In this case the source data is generated by the export function in GMail for your contacts.
After the modification outlined below (without RegEx) the result can be used to tidy up your contacts database and re-import it to GMail or to MS Outlook.
Yes, I am standing on the shoulders of #alan and #robinCTS. Thank you both.
Instructions in 5 steps:
use Notepad++ / find replace / extended search mode / wrap around = on
-1- replace all [CRLF] with a unique set characters or a string (I used [~~])
find: \r\n and replace with: ~~
The file contents are now on one line only.
-2- Now we need to separate the header line. For this move to where the first record starts exactly before the 88th. comma (including the word after the 87th. comma [,]) and enter the [CRLF] manually by hitting the return key. There are two lines now: header and records.
-3- now find all [,~~] and replace with [,\r\n] The result is one record per line.
-4- remove the remaining [~~] find: ~~ and replace with: [ ] a space.
The file is now clean of unwanted [CRLF]s.
-5- Save the file and use it as intended.
I have a document that has a range of numbers like this:
0300010000000394001001,27
0300010000000394001002,0
0300010000000394002001,182
0300010000000394002002,51
0300010000000394003001,156
0300010000000394003002,40
I need to find the new line character and replace with a number of spaces depending on the string length.
If it has 24 characters like this - 0300010000000394001002,0 then I need to replace the new line character at the end with 5 blank spaces.
If it has 25 characters like this - 0300010000000394002002,51 then I need to replace the new line character at the end with 4 blank spaces and so on.
In my text editor I can use find and replace. I search for the line length by ^(.|\s){24}$ for 24 characters - but this will obviously replace the whole line and I only need to replace the new line character at the end.
I want to specify a new line character AFTER ^(.|\s){24}$. Is this possible?
It sounds like you need two things.
Multi-line Mode (See "Using ^ and $ as Start of Line and...")
Backreferencing
Most editors that support regex support these naturally, but you'll have to let us know what editor you're using for us to be specific. Without knowing what editor you're using, all I can say is that you want to do some combination of the following:
regex subst
----- -----
^(.{24})\n $1 <-- there are spaces here
^(.{24})^M \1 <-- there are spaces here
^(.{24})\s ^^^^^