简体   繁体   中英

Regular Expression for finding keyword line and adding search range as a new column - Notepad++

I am looking for some help to create a regular expression/macro to do below in Notepad++:

  1. There is a section in the top portion. 8th column is the keyword to search for. EX: search word in Line 1 is: 3vynfaux5x7f6
  2. There are many other lines between these two sections.
  3. Second section has details for the keywords. Keyword is the starting word of the line in this section.
  4. On the matching line in second section, search for below:
    • Text between [U]:' '[/U] Ex:user1
    • Text between [D]:' '[/D] Ex:report1
    • Text between [S] [/S] Ex:datalayer1
  5. Add each of the text above as a new column, in the first section to the matching keyword line, ie 3vynfaux5x7f6
  6. Note that second section lines were shortened and indicated with 'very long SQL ~ 5000 chars' as they are too long.

Thank you very much in advance!

Below is the content to search:

 2   604 BOD9A     SvcAcct_OP 2019-03-20 15:36:51  2019-03-20 17:10:43  >60  3vynfaux5x7f6     8     43,028,307     21,477,582
 1  1423 BOD9A     SvcAcct_OP 2019-03-20 15:27:02  2019-03-20 15:45:17  >120 d943r2yqhrmxb     8     23,474,241     11,727,495
 2   285 BOD9A     SvcAcct_OP 2019-03-20 15:59:39  2019-03-20 17:11:09  >60  2akbrbykkfra8     8     19,728,513      9,685,044
 1  1648 BOD9A     SvcAcct_OP 2019-03-20 16:02:48  2019-03-20 17:11:12  >60  268g625syz3cu     8     15,220,260      5,812,065
 2   537 BOD9A     SvcAcct_OP 2019-03-20 15:49:42  2019-03-20 17:11:05  >60  ftgd185xum5jv     8      9,626,463     11,167,992

<many lines>

02v7k06k2zux6  insert into PRMTR_VAL_TXT AS Twin, PRCS_ID AS AppCode, SUBPRCS_ID AS SubAppCode, MAX_PRCS_TS AS ProcDate from (SELECT DISTINCT <very long SQL ~ 5000 chars>
1dmr7327m1sr6  SELECT /*+dynamic_sampling(11)*/  DISTINCT to_char()<very long SQL ~ 5000 chars>
203j3m9tkngyv  select  distinct decode(s.sql_id , null, s.prev_sql_id, s.sql_id ) as sql_id, t.piece, t.sql_text from    gn s, gtex t t where   decode(s.sql_id , null, s.prev_sql_id, s.sql_id) = t .sql_id and             s.username <> ' ' and s.username <> 'BKU CTRL' and s.username <> 'DBSNMP' and s.username <> 'SYS' and          s.sid not in (select sid from ion where qcsid! =sid) order by 1, 2
3vynfaux5x7f6  SELECT   TB_TB_NAME_LINE<very long SQL ~ 5000 chars> /* [TT][U]:'user1'[/U][D]:' report1'[/D][Q]:'BODW9A':'Query 1' :'DPUNI VERS'[/Q][S] datalayer1 [/S][A]'BOB'[/A][/ TT] */

268g625syz3cu  SELECT   TB_NAME_LINE<very long SQL ~ 5000 chars> /* [TT][U]:'user2'[/U][D]:' report2'[/D][Q]:'BODW9A':'Query 1' :'DPUNI VERS'[/Q][S] datalayer2 [/S][A]'BOB'[/A][/ TT] */
29bdpm894vydq  declare   Lines sys.dbms_output.chararr; begin   :NumLines := 10 ;   sys.dbms_output.get_lines(lines => Lines, numlines => :NumLi nes);   if :NumLines > 0 then :Line0 := Lines(1); end if;   if : NumLines > 1 then :Line1 := Lines(2); end if;   if :NumLines > 2  then :Line2 := Lines(3); end if;   if :NumLines > 3 then :Line3  := Lines(4); end if;   if :NumLines > 4 then :Line4 := Lines(5) ; end if;   if :NumLines > 5 then :Line5 := Lines(6); end if; if :NumLines > 6 then :Line6 := Lines(7); end if;   if :NumLines  > 7 then :Line7 := Lines(8); end if;   if :NumLines > 8 then :L ine8 := Lines(9); end if;   if :NumLines > 9 then :Line9 := Line s(10); end if; end;
2abw7qg0jz5mx  SELECT   TB_CHH_ NBR<very long SQL ~ 5000 chars> /* [TT][U]:'user3'[/U][S]datalayer3[/S][A]' BOBJ'[/A][/TT] */
2akbrbykkfra8  SELECT   TB_D_NAME_LINE<very long SQL ~ 5000 chars> /* [TT][U]:'user4'[/U][D]:' report4'[/D][Q]:'TWIN9A':'Query 1' :'DPUNI VERS'[/Q][S] datalayer4 [/S][A]'BOB'[/A][/ TT] */
2ba11aarc5r8r  SELECT   substr(TE_TXT<very long SQL ~ 5000 chars> /* [TT][U]:'user5'[/U][D]:'report5'[/D][Q]:'TWIN9 A':'Query 1 with DepMthy' :'DPUNIVERS'[/Q][S]datalayer5[/S][A]'BOB'[/A][/TT] */

Here is final output of first section:

 2   604 BOD9A     SvcAcct_OP 2019-03-20 15:36:51  2019-03-20 17:10:43  >60  3vynfaux5x7f6     8     43,028,307     21,477,582     user1     report1     datalayer1
 1  1423 BOD9A     SvcAcct_OP 2019-03-20 15:27:02  2019-03-20 15:45:17  >120 d943r2yqhrmxb     8     23,474,241     11,727,495
 2   285 BOD9A     SvcAcct_OP 2019-03-20 15:59:39  2019-03-20 17:11:09  >60  2akbrbykkfra8     8     19,728,513      9,685,044     user4     report4     datalayer4
 1  1648 BOD9A     SvcAcct_OP 2019-03-20 16:02:48  2019-03-20 17:11:12  >60  268g625syz3cu     8     15,220,260      5,812,065     user2     report2     datalayer2
 2   537 BOD9A     SvcAcct_OP 2019-03-20 15:49:42  2019-03-20 17:11:05  >60  ftgd185xum5jv     8      9,626,463     11,167,992

Try with this:

Search:

(\b([a-z0-9]{13})\b.*+)(?=[\s\S]+^\2.*\[U\]:?+'?+\s*([^[]+?)\s*'?\[\/U\].*\[D\]:?+'?+\s*([^[]+?)\s*'?\[\/D\].*\[S\]:?+'?+\s*([^[]+?)\s*'?\[\/S\])

Replace by:

\1     \3     \4     \5

You have a demo here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM