Page 1 of 1

Is Texpipe able to do that ?

Posted: Fri Apr 18, 2008 6:59 pm
by LDMGroup
I'm evaluating Textpipe, I've different text files, each text file is like that

Text1.txt
Name:Alfred
Surname:Brown
City:London
CarType:Ford
CarModel:Mustang

Text2.txt
Name:Bob
Surname:White
CarType:Mercedes

Text3.txt
Name:Lisa
City:Manchester
CarType:BMW
CartModel:320 Convertible

Using the demo I managed to get this output on each line:

Code: Select all

Alfred\tBrown\tLondon\tFord\tMustang\r\n
Bob\tWhite\tMercedes\r\n
Lisa\tManchester\tBMW\t320 Convertible\r\n
What I would like to get as result is:

Code: Select all

Alfred\tBrown\tLondon\tFord\tMustang\r\n
Bob\tWhite\t\tMercedes\t\r\n
Lisa\t\tManchester\tBMW\t320 Convertible\r\n
So I get the same type of field on the same column, how I can do that with Textpipe ?

Re: Is Texpipe able to do that ?

Posted: Mon Apr 21, 2008 2:43 pm
by DataMystic Support
Hi there,

You need to use optional fields in a pattern match to allow for the missing fields. Which fields are always present and which ones are optional?

Re: Is Texpipe able to do that ?

Posted: Tue Apr 22, 2008 2:21 am
by LDMGroup
What do you mean with optional fields ? Name and CarType fields are always present Surname, City, CarModel are optional.
Thank you

Re: Is Texpipe able to do that ?

Posted: Tue Apr 22, 2008 8:26 am
by DataMystic Support
For example, an EasyPattern search/replace

[ 'Name:', capture( 1+ not cr or lf) as 'Name', cr, lf,
optional( 'Surname:', capture( 1+ not cr or lf) as 'Surname', cr, lf ),
optional( 'City:', capture( 1+ not cr or lf) as 'City', cr , lf ),
'CarType:', capture( 1+ not cr or lf) as 'CarType', cr, lf,
longest optional( 'CarModel:', capture( 1+ not cr or lf) as 'CarModel' ) ]

Replace with:

@Name,@Surname, @City, @CarType, @CarModel

Re: Is Texpipe able to do that ?

Posted: Tue Apr 22, 2008 9:23 pm
by LDMGroup
It works, thank you Simon!