The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Split a file with no pattern -- Split, Csplit, Awk madhunk UNIX for Dummies Questions & Answers 10 12-17-2007 12:57 PM
Clouds (Partially Order Sets) - Streams (Linearly Ordered Sets) - Part 2 iBot Virtualization and Cloud Computing 0 07-28-2007 07:40 AM
Clouds (Partially Order Sets) – Streams (Linearly Ordered Sets) - Part 1 iBot Complex Event Processing RSS News 0 07-28-2007 07:40 AM
IP Security file sets zuessh AIX 3 04-26-2007 04:52 AM
FILE SETS in unix Aparna_A UNIX for Advanced & Expert Users 2 08-14-2006 04:12 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-22-2008
ChicagoBlues ChicagoBlues is offline
Registered User
  
 

Join Date: Jan 2008
Location: Chicago
Posts: 77
split a file with unique sets

This may sound like a trivial problem, but I still need some help:

I have a file with ids and I want to split it 'n' ways (could be any number) into files:

1
1
1
2
2
3
3
4
5
5

Let's assume 'n' is 3, and we cannot have the same id in two different partitions. So the partitions may look like (1,1,1,), (2,2,3,3),(4,5,5).

Thanks guys,

- CB
  #2 (permalink)  
Old 10-22-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
You're aware there's a limited number of combinations for a given fixed number of ids, right?
So, if you have 1 1 1 2 2 3 3 4 5 5 in the example you gave, and this happens more than once, the first partition could be (1,1,1),(2,2,3,3),(4,5,5) and a second occurrence of those ids could generate a partition like (1,1), (1, 2,2,3,3),(4,5,5), right?
  #3 (permalink)  
Old 10-22-2008
ChicagoBlues ChicagoBlues is offline
Registered User
  
 

Join Date: Jan 2008
Location: Chicago
Posts: 77
The second combination that you listed is incorrect because partition 1 and 2 both have id '1' in them.

Thanks,

- CB
  #4 (permalink)  
Old 10-22-2008
redoubtable redoubtable is offline
Registered User
  
 

Join Date: Aug 2008
Location: Portugal
Posts: 242
I don't understand what you want then. Give me an example, if I have the same ID twice, how should the program handle it?
  #5 (permalink)  
Old 10-22-2008
ChicagoBlues ChicagoBlues is offline
Registered User
  
 

Join Date: Jan 2008
Location: Chicago
Posts: 77
I was hoping for a better solution, but here is a crude way that i thought of:

1. split the file 'n' ways (n=3 for this example):

part 1 part 2 part 3
1 2 3
1 2 4
1 3 5

2. if n%(size of orig file) = 3%10 > 0 then append remaining id to the last partition

part 3
3
4
5
5

3. Compare part 1 with part 2 and see if ids are matched. If found, then move row from part 2 to part 1. Move to the next part and do the same.

part 1
1
1
1

part 2
2
2
3
3

part 3
3
4
5
5
Hopefully, someone will present a sleeker solution with some syntax.

Thanks,

- CB
  #6 (permalink)  
Old 10-22-2008
ChicagoBlues ChicagoBlues is offline
Registered User
  
 

Join Date: Jan 2008
Location: Chicago
Posts: 77
by the way, the original file is sorted by id
  #7 (permalink)  
Old 10-22-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,763
The OP wants all the 1's in a single file, 2's in a single file possibly with all 3's in the same file as well.

The problem is you have to know the split count as well as the complete key list and count of unique keys and how to group them before you attempt a split. I would create a list of unique key fields, divide the count by 3 and let any extras fall into the last split.

The problem with this is that you can get splits of enormously different sizes depending on how skewed the distribution of keys is in the data file. It defeats splitting altogether - IMO. And what happens when you ask for more splits than there are keys?

The only thing that that makes sense to me is a one-to-one split - one distinct key per file or leave everything in one big file.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0