Would like to Retain a line if following match a pattern?

Get help with installation and running here.

Moderators: DataMystic Support, Moderators, DataMystic Support, Moderators, DataMystic Support, Moderators

Post Reply
osiwan
Posts: 2
Joined: Thu May 12, 2005 11:04 pm

Would like to Retain a line if following match a pattern?

Post by osiwan »

Hello,
I'm new to TextPipe.
I would like to remove line matching a pattern but not if the following line contains another patern

Here my file.
Support #1 : "Full"
Restore started 13:11
Directory\\MOZART\G$\
mirror.log 1359483 31/03/05 18:31
robo.bat 229 31/03/05 18:10
Directory\\MOZART\G$\DATA
Directory\\MOZART\G$\DATA\SYSTEM
desktop.ini <H> 65 28/04/05 11:18

If would like to keep line containing "/"
Remove line started by Directory only il the following line do no contains "/"

Result should be:
Directory\\MOZART\G$\
mirror.log 1359483 31/03/05 18:31
robo.bat 229 31/03/05 18:10
Directory\\MOZART\G$\DATA\SYSTEM
desktop.ini <H> 65 28/04/05 11:18

Thanks for any advice.
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Post by DataMystic Support »

Try this perl pattern

Code: Select all

(Directory[^\r\n]*\r\n)[^\r\n/]*\r\n
Replace with

Code: Select all

$1
Bonus marks if you can tell me what this does!
osiwan
Posts: 2
Joined: Thu May 12, 2005 11:04 pm

Post by osiwan »

I've done a test with a remove matching and remove non-matching, but I should have missed something. I get the same output or a empty one.

Regards.
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Post by DataMystic Support »

Ok. The best way to handle this is to mark the 'good' lines, then remove all other 'Directory' lines. Here is a filter list to do this:

|--Perl pattern [(Directory[^\r\n]*\r\n)([^\r\n]*/[^\r\n]*\r\n)] with [##$0]
| [ ] Match case
| [ ] Whole words only
| [ ] Case sensitive replace
| [ ] Prompt on replace
| [ ] Skip prompt if identical
| [ ] First only
| [ ] Extract matches
| Maximum text buffer size 4096
| [ ] Maximum match (greedy)
| [ ] Allow comments
| [X] '.' matches newline
| [ ] UTF-8 Support
|
|--Remove matching lines [^Directory]
| [ ] Include line numbers
| [ ] Include filename
| [ ] Match case
| [ ] Count matches
| Pattern type: 0
| Context before: 0
| Context after: 0
|
|--Perl pattern [##Directory] with [Directory]
Post Reply