Create file per country

Get help with installation and running here.

Moderators: DataMystic Support, Moderators

CRAIGER
Posts: 2
Joined: Tue Jul 24, 2007 2:25 am

Create file per country

Postby CRAIGER » Mon Jul 30, 2007 1:04 am

Another small problem:

Format:
1001|First Company|USA|First Address|other fields

I have several hundreds of files with random filename with this format.

I would like to create USA.dump file and UK.dump file etc per each country found in all files.

I made extract with all Country names and removed duplicates and sorted.

Now how can I automatic create files USA.dump with all data from USA in this file and for all other countries found?

(I hope my question is clear)

Added:
So I want to end up with USA.dump UK.dump CANADA.dump etc (each file containing the data belonging to the country, so first line in USA.dump would be: 1001|First Company|USA|First Address|other fields..

CRAIGER

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

Postby DataMystic Support » Mon Jul 30, 2007 10:13 am

Hi Craig,

Use a Secondary Output Filter (Filters\Special\Secondary output filter) as a subfilter of Filters\Restrict\Matching lines (grep), to send matching output for USA, UK etc to the appropriate output file.
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

Gasoline
Posts: 2
Joined: Wed Apr 23, 2008 5:11 am

Re: Create file per country

Postby Gasoline » Wed Apr 23, 2008 6:05 am

Hi! I'm stupid! Can you try to make this in your program and then explain for dummy? Please! :oops:

in other words

i have file all.txt:
1001|First Company|USA|First Address
1002|Second Company|USA|Second Address
1004|First Company|UK|First Address
1007|2 Company|UK|2 Address
1008|3 Company|UK|3 Address
1008|67 Company|CA|43 Address
1008|23 Company|CA|63 Address

i need 3 files in output:
USA.txt:
1001|First Company|USA|First Address
1002|Second Company|USA|Second Address
UK.txt:
1004|First Company|UK|First Address
1007|2 Company|UK|2 Address
1008|3 Company|UK|3 Address
CA.txt:
1008|67 Company|CA|43 Address
1008|23 Company|CA|63 Address

Gasoline
Posts: 2
Joined: Wed Apr 23, 2008 5:11 am

Re: Create file per country

Postby Gasoline » Wed Apr 23, 2008 6:10 am

Forgot term:
Obviously, I have a list of coutries: USA, UK, CA

In which format enter them into "restrict to lines matching" line?

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

Re: Create file per country

Postby DataMystic Support » Wed Apr 23, 2008 11:04 am

Just one country per line e..g

USA
UK
CA
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments

DFH
Posts: 636
Joined: Sun Dec 09, 2007 2:49 am
Location: UK

Re: Create file per country

Postby DFH » Wed Apr 23, 2008 5:52 pm

Surely this task was so simple it could have been done just by means of a CMD script using the Windows find command?

Code: Select all

find "|USA|" <inputfile >USA.txt
find "|UK|" <inputfile >UK.txt
...etc
Best regards,

David

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

Re: Create file per country

Postby DataMystic Support » Wed Apr 23, 2008 10:56 pm

With TextPipe you can perform the sort and remove duplicates, and the sending of the country-specific data, all in one step.

Code: Select all

|--Ascending ANSI sort (case sensitive), remove duplicates, length 4096
|   
|--Restrict to lines matching [\|US\|]
|  |  [ ] Include line numbers
|  |  [ ] Include filename
|  |  [ ] Match case
|  |  [ ] Count matches
|  |  Pattern type: 1
|  |  Context before: 0
|  |  Context after: 0
|  |
|  |--Merge output to file c:\USA.txt
|  |   
|  +--Remove all
|     
|--Restrict to lines matching [\|UK\|]
|  |  [ ] Include line numbers
|  |  [ ] Include filename
|  |  [ ] Match case
|  |  [ ] Count matches
|  |  Pattern type: 1
|  |  Context before: 0
|  |  Context after: 0
|  |
|  |--Merge output to file c:\UK.txt
|  |   
|  +--Remove all
|     
..etc..
Regards,

Simon Carter, http://DataMystic.com/forums/index.php
http://PredictBGL.com - Insulin dose calculator for Type 1 diabetes
http://DownloadPipe.com - 250,000 free software downloads
http://DetachPipe.com - send huge email attachments


Return to “TextPipe Tips and Tricks, Questions and Support”

Who is online

Users browsing this forum: No registered users and 3 guests