find and delete lines based on variable

find and delete lines based on variable

5

    Apr 23, 2015#1

    I'd like to find a way for UE to search through a directory of files, find a specified variable, ignore parts of lines and delete a specified number of lines. I doubt I'm explaining this well at all but here is an example of what I'd like to be able to do.

    I would like UE to find instances where

    Code: Select all

    [POI]
    Type=0x6004
    Label=DRAFT WORKS BREWERY
    Data4=(46.87774,-114.00350)
    [END]
    
    
    [POI]
    Type=0x6004
    Label=DRAFT WORKS BREWERY
    Data0=(46.87774,-114.00350)
    [END]
    So what I would like UE to do is find instances where Type=0x6004 and Data0= are present and delete all 5 lines of text. Can someone point me in the right direction to make this happen? Thanks

    6,603548
    Grand MasterGrand Master
    6,603548

      Apr 24, 2015#2

      With Perl regular expression enabled search for (?s)^\[POI\](?:.(?!\[END\]))+?Type=0x6004(?:.(?!\[END\]))+?Data0=.+?\[END\][\t\r\n ]*

      (?s) ... flag for dot matches also carriage return and line-feed.

      ^ ... start each search at beginning of a line.

      \[POI\] ... find the string [POI]. Square brackets are used in Perl regexp to define a character set and therefore the square brackets must be escaped with a backslash to find those 2 characters.

      (?:...)+? ... defines a non-capturing group with an expression which must be applied 1 or more times non greedy for a positive match.

      .(?!\[END\]) ... any character where next to found character [END] is NOT found. (?!...) is a negative look-ahead.

      The first non-capturing group matches therefore a string with 1 or more characters non greedy up to either Type=0x6004 or [END]. In case of [END] is found first, the entire search expression becomes negative and therefore Perl regular expression starts the search again with a search for [POI] at beginning of a line.

      The second non-capturing group matches a string with 1 or more characters non greedy up to either Data0= or [END]. In case of [END] is found first, the entire search expression becomes negative for current block starting with [POI] and ending with [END].

      [\t\r\n ]* ... a character set with tab, carriage return, line-feed and space which can be found 0 or more times greedy. This expression matches line termination after [END] and all blank lines below up to next [POI] or end of file.

      The replace string is an empty string.
      Best regards from an UC/UE/UES for Windows user from Austria

      5

        Apr 24, 2015#3

        Perfect! Thank you so much!