James Upson
James Upson

Reputation: 65

Deleting everything after matched line

I have a standard txt file. I want to delete everything after a certain point. I have captured everything I want to keep using the following regex:

(.+\t\d+\t.+\t\d\t.+\t\d.+)

In the txt file, there will be a line that has Row Count \t (followed by row count number)

Example: AB\t1234567890\tStudent Individual Monthly PAID\t1\t.012345\t.012345\tABCD12345678\tFuck Russt\tT-Wayne\t1\t1\tABCD12345678\t0\t123\tEntertainment\tA12342A1234567890A Row Count\t123456 Abcdefghij Abcd\tAbcdefghij Abcd\tAbcdefgh\tAbc Abcdefg Abcde AB\tFamily Monthly Gratis Trial\t1234\t0.00 AB\tIndividual Monthly Gratis Trial\t12345\t0.00 AB\tStudent Monthly Gratis Trial\t1234\t0.00 AB\tFamily Introductory OFFER\t123456\t123.45 AB\tIndividual Introductory OFFER\t123456\t1234.56 AB\tStudent Individual Introductory OFFER\t12345\t123.45 AB\tFamily Monthly PAID\t1234567\t12345.67 AB\tIndividual Annual PAID\t12345\t123.45 AB\tIndividual Monthly PAID\t1234567\t12345.67 AB\tStudent Individual Monthly PAID\t123456\t1234.56

Desired Result: AB\t1234567890\tStudent Individual Monthly PAID\t1\t.012345\t.012345\tABCD12345678\tFuck Russt\tT-Wayne\t1\t1\tABCD12345678\t0\t300\tEntertainment\tA12342A1234567890A

I want to delete the 'Row Count' row as well as everything that follows afterwards.

Any help on this would be greatly appreciated

Upvotes: 1

Views: 86

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626728

Assuming (.+\t\d+\t.+\t\d\t.+\t\d.+) matches the point after which you want to remove everything in the file to its end, you may append (?s).* to your pattern and replace with $1, a placeholder containing the text captured in the first group.

Do not enable . matches newline option. (?s) will make the next . match any chars including line break chars, it is an inline DOTALL modifier variant while the previous ones will still match all chars but line break chars.

enter image description here

Upvotes: 1

Related Questions