1

I have a text file that I need to extract specific data elements from.

Example text:

HIABK>Z48812~HIAPR>Z48812~HI*ABF>I2510*ABF>K810*ABF>I10*ABF>J449*ABF>F329*ABF>F419*ABF>I252~NM1*71*1*Darbinian*Sevak****XX*1306859178~LX*1~SV2*0551*HC>G0154*250*UN*4~DTP*472*D8*20180202~REF*6R*74990814~HL*3*1*22*0~HIABK>N390~HIAPR>N390~HI*ABF>B9620*ABF>B961*ABF>N319*ABF>G8220*ABF>S12300S*ABF>G9520*ABF>Z1612~NM1*71*1*Boonyaputthikul*Robert****XX*1700198801~LX*1~SV2*0551*HC>G0154*250*UN*4~DTP*472*D8*20180125~REF*6R*74990810~

I want to extract:

Darbinian Sevak 1306859178

Boonyaputthikul Robert 1700198801

How can do this with notepad++?

  • Welcome to Super User! What have you tried so far? Is your data formatted exactly as you have it above- one continuous line? – bertieb Apr 4 '18 at 15:16
  • You can use regex or you can use any programming language to do it. – GoutamS Apr 4 '18 at 15:35
  • Yes one continuous line and I can seem to get the expression correct in regex – Missy Apr 4 '18 at 15:42
  • What are the rules used for extraction? – Toto Apr 4 '18 at 15:48
  • I'm not certain what you mean by rules for extraction. I have a text file and right now I literally do a ctrl F to find NM1*71*1*, then I copy and paste the text following till the ~ into another document by hand. Problem is I can easily have over 1000 instances of NM1*71*1* in a document and I have 250 documents to go through. – Missy Apr 4 '18 at 16:37
2

This can't be done in a single step with Notepad++, you could do:

First step:

  • Ctrl+H
  • Find what: (?:^|\G).+?NM1\*71\*1\*(.+?)\*{4}XX\*(\d+)
  • Replace with: $1 $2\n
  • check Wrap around
  • check Regular expression
  • DO NOT CHECK . matches newline
  • Replace all

Explanation:

(?:             : non capture group
  ^             : beginning of line
 |              : R
  \G            : position of last match
)               : end group
.+?             : 1 or more any character, not greedy
NM1\*71\*1\*    : literally "MN1*71*1*", asterisk have to be escaped
(.+?)           : group 1, 1 or more any character, not greedy
\*{4}XX\*       : 4 asterisks, XX, then 1 asterisk 
(\d+)           : group 2, 1 or more digit

Replacement:

$1      : content of group 1
        : a space
$2      : content of group 2
\n      : line feed, you could change it for the linebreak you need

Result for given example:

Darbinian*Sevak 1306859178
Boonyaputthikul*Robert 1700198801
LX*1~SV2*0551*HC>G0154*250*UN*4~DTP*472*D8*20180125~REF*6R*74990810~

In a second step, you have to delete the last line.

  • Thank you so tremendously much, I will not forget how to do this! Works perfectly. – Missy Apr 4 '18 at 18:41
  • @Missy: You're welcome, glad it helps. – Toto Apr 4 '18 at 18:43
  • @Missy: Feel free to mark the answer as accepted, see: superuser.com/help/someone-answers – Toto Apr 4 '18 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.