Deleting sections of data that start and end with the same characters based on a string of text contained within the section
-
Hello there,
I have a file that contains repeated sections of data, starting with a ‘{’ and ending with a ‘},’ but the data within these sections changes (field names stay the same) i.e. ‘identificationNumber’, ‘sizeandtypecode’ etc.
I need a way to be able to search the whole file for specific identification numbers but delete the whole section the id number is contained within. - starting with { and ending with },{
“identificationNumber” : “ABCD1234567”,
“sizeAndTypeCode” : “45G0”,
“shippingLine” : “MSC”,
“shipsAgent” : “PORTSATLANTIC”,
“transitDirection” : “EXPORT”,
“isLaden” : true,
“grossWeightKG” : 27468,
“portOfDischargeCode” : “BEANR”,
“finalPortOfDischargeCode” : “USNYC”,
“seals” : [
{
“number” : “0990682”,
“conditionCode” : “INTACT”,
“sealedBy” : “carrier”
}
]
},
{
“identificationNumber” : “ABCD4561239”,
“sizeAndTypeCode” : “45G0”,
“shippingLine” : “MSC”,
“shipsAgent” : “PORTSATLANTIC”,
“transitDirection” : “EXPORT”,
“isLaden” : true,
“grossWeightKG” : 27468,
“portOfDischargeCode” : “BEANR”,
“finalPortOfDischargeCode” : “USNYC”,
“seals” : [
{
“number” : “0990682”,
“conditionCode” : “INTACT”,
“sealedBy” : “carrier”
}
]
},
{
“identificationNumber” : “ABCD7894223”,
“sizeAndTypeCode” : “45G0”,
“shippingLine” : “MSC”,
“shipsAgent” : “PORTSATLANTIC”,
“transitDirection” : “EXPORT”,
“isLaden” : true,
“grossWeightKG” : 11800,
“portOfDischargeCode” : “BEANR”,
“finalPortOfDischargeCode” : “USNYC”,
“seals” : [
{
“number” : “0990288”,
“conditionCode” : “INTACT”,
“sealedBy” : “carrier”
}
]
},Thanks in advance,
Ruby
-
Hello, @ruby-Pierce and All,
First, I don’t know if you do use the simple double quote char
"
or if you need the opening and ending quotation marks ( the“
and”
chars with Unicode code-points\x{201C}
and\x{201D}
), automatically provided by ourNodeBB
site !Anaway, here is a solution :
-
Open the Replace dialog (
Ctrl + H
)- SEARCH
^{\R“identificationNumber” : “xxxx#######”,(?s).*?^},(\R|\z)
if couples of“
and”
are used
OR
- SEARCH
^{\R"identificationNumber" : "xxxx#######",(?s).*?^},(\R|\z)
if the"
char is only used
- SEARCH
-
REPLACE
Leave EMPTY
-
Tick the
Wrap around
option, preferably -
Select the
Regular expression
search mode -
Click on the
Replace
orReplace All
buttons
Of course, replace in the search regex, any
x
char by a letter and any#
by a digit !Best Regards,
guy038
-