Page 1 of 1

Newbie needs help..

Posted: Wed Sep 23, 2009 9:51 am
by rukiddin
This should be an easy one. I'm not a programmer, so I've been hacking my way through TextPipe and just need a little help to finish up.

What I've got is an old school item status report that details about 30-40 items. Each item has roughly 20 lines of information. I only need to extract 4 of the lines for my purposes. I can easily write a filter to extract each of the 4 lines separately, but I haven't been able to figure out how to extract all 4 of the lines into one output file. Ideally, I would then like to take the 4 lines of output per item and put them on one single line, so I would end up with the detail I need for the 30-40 products in a file that has only 30-40 lines. (which will make it very easy to import into Excel)

I'm using "Extract lines matching perl pattern [using 1 line of each text below]"

^\w{2}\d{4}
^TTL
OPEN RMA
^\|TOT

If I run this 4 times (once for each line of text), I get 4 files which I can easily merge together, but I figure I should be able to run this just once and get the output I need.

At the end, I want to take the output and combine each output onto 1 line for each product so that I end up with a 30-40 line output. (I know that would involve a search and replace of some sort)

Any help would be appreciated.

Thanks

Mike

Re: Newbie needs help..

Posted: Wed Sep 23, 2009 4:20 pm
by DataMystic Support
Several approaches Mike.

You could first REMOVE non-matching lines, using
Filters\Remove\Remove lines\Remove non-matching lines

Then you'd just be left with what you want. Let me know if this helps.

Re: Newbie needs help..

Posted: Wed Sep 23, 2009 11:58 pm
by rukiddin
It's easier to identify the lines I want to keep, only because they are always there.. Most of the other lines are more repetitive, and not as easy to uniquely identify. I will give that another try though.

Re: Newbie needs help..

Posted: Thu Sep 24, 2009 2:43 am
by rukiddin
Ok, I figured it out using the Remove non-matching lines filter. Thanks for that. Now I need to figure out how to put each item's results on a single line (instead of 4 separate lines). I know that involves Search and Replace. The Syntax for the commands is a bit technical for me.. I know it goes something like

([^\r\n]*)\r\n([^\r\n]*?) <- Can someone translate this into English so I can better understand how it works?
Replace with
$1$2

I know \r is a carriage return, and \n is a newline, but I'm unable to actually read and understand what the above lines actually means. I need to modify it to work with 4 lines of output, vs. 2 lines.

Thanks

Mike

Re: Newbie needs help..

Posted: Thu Sep 24, 2009 2:44 am
by rukiddin
Also, to throw a curve ball.. one of the 4 lines isn't always there. The first three are always present, the 4th is more of a grand total from the report, so it shows up randomly after the 3rd line.

Re: Newbie needs help..

Posted: Thu Sep 24, 2009 6:20 am
by DataMystic Support
For clarity, try this EasyPattern,

[ capture( 0+ not cr or lf ), cr, lf,
capture( 0+ not cr or lf ), cr, lf,
capture( 0+ not cr or lf ), cr, lf,
capture( longest optional( 0+ not cr or lf ), cr, lf, )
]

Replace with
$1 $2 $3 $4\r\n

Re: Newbie needs help..

Posted: Thu Sep 24, 2009 7:11 am
by rukiddin
DataMystic Support wrote:For clarity, try this EasyPattern,

[ capture( 0+ not cr or lf ), cr, lf,
capture( 0+ not cr or lf ), cr, lf,
capture( 0+ not cr or lf ), cr, lf,
capture( longest optional( 0+ not cr or lf ), cr, lf, )
]

Replace with
$1 $2 $3 $4\r\n

If I only parse for the first 3 lines, and then use the above except for the 4th capture line it works PERFECT, however, if I add the 4th component, and the final capture, the output is screwed up. It has extra New lines, and seems to mess up the order of the other data. (Hard to explain.) Would it be because there is no reserved space for the 4th item when it's not there?

Re: Newbie needs help..

Posted: Thu Sep 24, 2009 9:03 am
by DataMystic Support
sorry, use

[ capture( 0+ not cr or lf ), cr, lf,
capture( 0+ not cr or lf ), cr, lf,
capture( 0+ not cr or lf ), cr, lf,
capture( longest optional( 0+ not cr or lf ) ), cr, lf,
]

The trailing CR/LF should not have been part of the capture.

Re: Newbie needs help..

Posted: Fri Sep 25, 2009 10:17 am
by rukiddin
DataMystic Support wrote:sorry, use

[ capture( 0+ not cr or lf ), cr, lf,
capture( 0+ not cr or lf ), cr, lf,
capture( 0+ not cr or lf ), cr, lf,
capture( longest optional( 0+ not cr or lf ) ), cr, lf,
]

The trailing CR/LF should not have been part of the capture.
That seems to have helped a little bit, but didn't solve the problem. It still seems to be inserting carriage returns, and the line I'm trying to add to the end of a line when it appears is still on it's own line.

Re: Newbie needs help..

Posted: Fri Sep 25, 2009 5:07 pm
by DataMystic Support
Ensure you don't have any trialing cr\lfs in the replace string - right-click and choose 'Show Special Characters'