Page 1 of 1

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

Posted: Thu May 12, 2005 11:27 pm
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.

Posted: Fri May 13, 2005 5:38 pm
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!

Posted: Fri May 13, 2005 7:11 pm
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.

Posted: Mon May 16, 2005 9:31 am
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]