Page 1 of 1

Create file per country

Posted: Mon Jul 30, 2007 1:04 am
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

Posted: Mon Jul 30, 2007 10:13 am
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.

Re: Create file per country

Posted: Wed Apr 23, 2008 6:05 am
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

Re: Create file per country

Posted: Wed Apr 23, 2008 6:10 am
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?

Re: Create file per country

Posted: Wed Apr 23, 2008 11:04 am
by DataMystic Support
Just one country per line e..g

USA
UK
CA

Re: Create file per country

Posted: Wed Apr 23, 2008 5:52 pm
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

Re: Create file per country

Posted: Wed Apr 23, 2008 10:56 pm
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..