Find One Line of Text, Then Backup the next Line Above & paste
-
I would like to do a Search & replace, but this is not as simple as I thouht.
Here is an example:
I want to find 2 DATE 1920
Then the next line it must equal 1 RESI Like shown below.
1 RESI
2 DATE 1920If all is TRUE, then Select the line having 1 RESI
Replace it with:
1 EVEN
2 TYPE 1920 US Federal CensusI need to do this with other dates, like 1800, 1810, 1820, 1830, etc.
Any help would be appreciated. Being doing a Find, conform next line equals 1 RESI then Selecting it and pasting new data.
Then repeat over and over. Have a large amount of data to go through. And the current way id very time consuming. -
Could you give us a “before” and “after”, using the
</>
button to format the text like:before
and
after
… and have the example have a few rows that will be replaced and a few that won’t.
I need to do this with other dates
Also, please make it more clear whether the other dates need to be handled in the same regex, and whether they will be replaced with the same text or different text depending on date (if the only thing different between the replacements is that it will be
2 TYPE #### US Federal Census
, the #### can easily be grabbed by the FIND regex and placed in the replace; if it’s more complicated than that, you’ll have to give more detail.)----
Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the
</>
toolbar button or manual Markdown syntax. To makeregex in red
(and so they keep their special characters like *), use backticks, like`^.*?blah.*?\z`
. Screenshots can be pasted from the clipboard to your post usingCtrl+V
to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries. -
@Bill-Holder said in Find One Line of Text, Then Backup the next Line Above & paste:
I want to find 2 DATE 1920
Then the next line it must equal 1 RESI Like shown below.
1 RESI
2 DATE 1920Bad information right out of the box. :-(
This one might take more effort to extract the real problem than to arrive at a solution.
Good luck, I’m moving on… -
First I copy in the following two lines:
1 EVEN
2 TYPE 1940 US Federal CensusSearch for 2 DATE 1940 and finding it. Next look t the line of datadirectly above it if reads only 1 RESI the do a copy and replace on 1 RESI after making the changes, and continue searching until all of that criteria is met.
On to the next year, 1935, Copy the next two lines
1 EVEN
2 TYPE 1935 US Federal CensusThen start again with 2 DATE 1935 and repeat again. When there are no more searches for 2 DATE 1935 with the line above containing only this 1 RESI, then start with another date.
So when done there should not be any more lines like this:
1 RESI
2 DATE xxxx (No 4 Digits by itself.)There will be other 1 RESI date containing addded information like:
1 RESI 233 E. Young
2 DATE 23 Apr 1940The 2 DATE line must contain only 4 digits
Yes, the date of 1920 will possibliy change starting from 1750 to 1940, (every 10 years, as when the census was taken throughout the US in many, many areas) also it will include the year 1935.
But the “US Federal Census” will not change.
When finished, start over with a new year, amd repeat again. This occours for each year.This one file has a total of 74,714 lines of data in it.
Another file, has 8,741,009 lines of data in it. These are just two of the many files that I am currently on.Here is the real data for just one person:
0 @I115@ INDI
1 NAME M. /W./
2 GIVN M.
2 SURN W.
2 SOUR @S4@
3 PAGE accessed 24 Feb 2021), entry for M. W.
4 CONC person ID.
3 QUAY 3
1 SEX F
1 BIRT
2 DATE 16 Nov 1919
2 PLAC , , Maine
2 SOUR @S4@
3 PAGE accessed 24 Feb 2021), entry for M. W.
4 CONC person ID.
3 QUAY 3
1 DEAT
2 DATE 7 Jan 1941
2 SOUR @S4@
3 PAGE accessed 24 Feb 2021), entry for M. W.
4 CONC person ID.
3 QUAY 3
1 _PPEXCLUDE
1 RESI
2 DATE 1920
2 PLAC , Cabell, West Virginia
2 SOUR @S4@
3 PAGE accessed 24 Feb 2021), entry for M. W.
4 CONC person ID.
3 QUAY 3
3 NOTE ;Contributor:
4 CONT
1 RESI
2 DATE 1930
2 PLAC , Cabell, West Virginia
2 SOUR @S4@
3 PAGE accessed 24 Feb 2021), entry for M. W.
4 CONC person ID.
3 QUAY 3
3 NOTE ;Contributor:
4 CONT
1 RESI
2 DATE 1935
2 PLAC Same Place
2 SOUR @S4@
3 PAGE accessed 24 Feb 2021), entry for M. W.
4 CONC person ID.
3 QUAY 3
3 NOTE ;Contributor:
4 CONT
1 RESI
2 DATE 1940
2 PLAC , Cabell, West Virginia
2 SOUR @S4@
3 PAGE accessed 24 Feb 2021), entry for M. W.
4 CONC person ID.
3 QUAY 3
3 NOTE ;Contributor:
4 CONT
1 _UID CD36422AB4882352D252C531182769341666
1 _FSFTID GMXQ-YHF
1 _FSLINK
1 CHAN
2 DATE 24 Feb 2021
3 TIME 23:56
1 FAMS @F48@
1 FAMC @F480@Please have a little care for I am 74 year of age, amd still learning.
Thanks
Bill -
Hello, @bill-holder a,d All,
Ah… OK ! So, I think that this following regex S/R should work :
SEARCH
(?-i)1 RESI\R2 DATE (\d{4})$
REPLACE
1 EVEN\r\n2 TYPE \1 US Federal Census
-
Open your file in N++
-
Open the Replace dialog (
Ctrl + H
)-
SEARCH
(?-i)1 RESI\R2 DATE (\d{4})$
-
REPLACE
1 EVEN\r\n2 TYPE \1 US Federal Census
-
Tick the
Wrap around
option -
Select the
Regular expression
search mode -
Click on the
Replace All
button
-
-
Close the Replace dilaog (
Esc
)
Et voilà !
Notes :
-
First, the
(?-i)
modifier forces the search to be sensitive to letter case -
Then, the regex engine looks for the string
1 RESI
, with this exact case, followed with line-ending characters\R
, itself followed with the next line : the stringDATE
, with that exact case, followed with a space char and a four digits number\d{4}
, which ends the line =>$
-
As the four digits number is surrounded between brackets
(....)
, it is stored as group1
-
In replacement, we rewrite the line
1 EVEN
, followed with line-ending characters\r\n
, itself followed with a next line : the stringTYPE
, followed with a space char, the contents as group1
(\1
), an other space char and, finally, the stringUS Federal Census
In your sample text, we get
4
occurrences and replacements :..... ..... 1 RESI ==> 1 EVEN 2 DATE 1920 ==> 2 TYPE 1920 US Federal Census ..... ..... 1 RESI ==> 1 EVEN 2 DATE 1930 ==> 2 TYPE 1930 US Federal Census ..... ..... 1 RESI ==> 1 EVEN 2 DATE 1935 ==> 2 TYPE 1935 US Federal Census ..... ..... 1 RESI ==> 1 EVEN 2 DATE 1940 ==> 2 TYPE 1940 US Federal Census ..... .....
Best Regards,
guy038
-
-
Thanks for all the hard work. It seems to be working, just a few minor glitches. But they are probably on my end. Will let you know more as to what I find later on.
Again, Thanks A Lot
Bill