Create file per country

Get help with installation and running here.

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

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

Create file per country

Post by CRAIGER »

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: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Post by DataMystic Support »

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.
Gasoline
Posts: 2
Joined: Wed Apr 23, 2008 5:11 am

Re: Create file per country

Post by Gasoline »

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

Post by Gasoline »

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: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Create file per country

Post by DataMystic Support »

Just one country per line e..g

USA
UK
CA
dfhtextpipe
Posts: 986
Joined: Sun Dec 09, 2007 2:49 am
Location: UK

Re: Create file per country

Post by dfhtextpipe »

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
David
User avatar
DataMystic Support
Site Admin
Posts: 2227
Joined: Mon Jun 30, 2003 12:32 pm
Location: Melbourne, Australia
Contact:

Re: Create file per country

Post by DataMystic Support »

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..
Post Reply