merging two files with sorted integers in c


 
Thread Tools Search this Thread
Top Forums Programming merging two files with sorted integers in c
# 1  
Old 12-21-2009
merging two files with sorted integers in c

Hi,

I want to merge two files with sorted integers. I want to merge two files to a single file such that there are no duplicates and the merged file should contain the integers in the sorted order. Just some idea or pointer to an implementation will help me a lot.


Thanks & Regards,
brett.
This User Gave Thanks to brett01 For This Post:
# 2  
Old 12-21-2009
Quote:
Originally Posted by brett01
Hi,

I want to merge two files with sorted integers. I want to merge two files to a single file such that there are no duplicates and the merged file should contain the integers in the sorted order. Just some idea or pointer to an implementation will help me a lot.


Thanks & Regards,
brett.
Hello brett,
there are several known algorithms for that purpose. I feel the K-way-merge algorithm is the best one that I have used for that purpose.
In addition to that you can put up a condition to remove the duplicate entries
Or otherwise you can first remove the duplicate entries from the two sources after/before sorting and then implement the K-way merge algorithm .
Feel free to reply if any doubts.
You would like to check this in case
http://sourceforge.net/projects/kwaymerge/
Regards.
# 3  
Old 12-21-2009
If the two files are already sorted, then
Code:
sort -mnu file1 file2

otherwise omit the m in the options.
# 4  
Old 12-21-2009
Looks like insertion sort could help with this problem.
# 5  
Old 12-21-2009
Quote:
Originally Posted by gaurav1086
Hello brett,
there are several known algorithms for that purpose. I feel the K-way-merge algorithm is the best one that I have used for that purpose.
In addition to that you can put up a condition to remove the duplicate entries
Or otherwise you can first remove the duplicate entries from the two sources after/before sorting and then implement the K-way merge algorithm .
Feel free to reply if any doubts.
You would like to check this in case
K-Way Merge | Get K-Way Merge at SourceForge.net
Regards.
Is the key way merge algorithm for already sorted files??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Is there a way to join 2 text files sorted by

Can anyone please help me i have 2 text files setup like the one below. Textfile1: randomemail1:randompassword1 randomemail2:randompassword2 randomemail3:randompassword3 randomemail4:randompassword4 randomemail5:randompassword5 Textfile2: randompassword1:randomphrase1... (8 Replies)
Discussion started by: nufc
8 Replies

2. Shell Programming and Scripting

Paste multiple files, but only the sorted head -50

Hello, I want to merge multiple files (under hundreds folders) side by side. File name are the same but folder are different. like folder1/same_name.txt folder2/same_name.txt folder3/same_name.txt ......Normally it can be done as paste /different_path*/same_name.txt > merged_file.txtbut... (2 Replies)
Discussion started by: yifangt
2 Replies

3. Shell Programming and Scripting

Grep float/integers but skip some integers

Hi, I am working in bash in Mac OSX, I have following 'input.txt' file: <INFO> HypoTestTool: >>> Done running HypoTestInverter on the workspace combined <INFO> HypoTestTool: The computed upper limit is: 11 +/- 1.02651 <INFO> HypoTestTool: expected limit (median) 11 <INFO> HypoTestTool: ... (13 Replies)
Discussion started by: Asif Siddique
13 Replies

4. Shell Programming and Scripting

sort the files based on timestamp and execute sorted files in order

Hi I have a requirement like below I need to sort the files based on the timestamp in the file name and run them in sorted order and then archive all the files which are one day old to temp directory My files looks like this PGABOLTXML1D_201108121235.xml... (1 Reply)
Discussion started by: saidutta123
1 Replies

5. Shell Programming and Scripting

combine multiple files by column into one files already sorted!

I have multiple files; each file contains a certain data in a column view simply i want to combine all those files into one file in columns example file1: a b c d file 2: 1 2 3 4 file 3: G (4 Replies)
Discussion started by: ahmedamro
4 Replies

6. UNIX for Dummies Questions & Answers

write a program in c in unix that display the files(includ sub-direc and files within) in a sorted

the sorting is based on name of file, file size modification time stamps o f file it should dislay the output in the following format "." and ".." enteries should be ignored please give some idea how to do it (1 Reply)
Discussion started by: pappu kumar jha
1 Replies

7. Shell Programming and Scripting

Editing lists of integers in 1d files with bash shell

Hi, I need a script that will: 1. Go through about 20 different folders, each containing about 20 1d files. The 1d files go something like this: 22.253 37.707 78.117 112.374 127.944 156.067 180.956 233.785 249.256 ... (1 Reply)
Discussion started by: ac130pilot
1 Replies

8. Shell Programming and Scripting

concatenate files sorted by date

I am a beginner in script writing, i tried to do the following I have a set of files sorted by date in the format YYMMDD.s and .x and .r I need to concatenate a header file to these sets of files so I used the following code echo "enter Swath number" read s echo "please enter first date and... (2 Replies)
Discussion started by: docaia
2 Replies

9. Shell Programming and Scripting

executing code on files in the sorted order -help!

Say i have 2 files in the giving format: file1 1 2 3 4 1 2 3 4 1 2 3 4 file2 1 2 3 4 1 2 3 4 1 2 3 4 I have a PERL code (loaned by one of u -i forgot who - thanks!) that extracts the 2nd column from each file and append horizontally to a new file: perl -ane 'push @{$L->}, $F; close... (1 Reply)
Discussion started by: epi8
1 Replies

10. Shell Programming and Scripting

Compare 2 sorted files

Hi all, please give me the commands using which i can compare 2 sorted files and get the difference in third file, indiating where the difference is from either file1 or file2. as: File1 (Original file) GARRY JOHN JULIE SAM --------------- File2 DEV GARRY JOHN JOHNIEE (7 Replies)
Discussion started by: varungupta
7 Replies
Login or Register to Ask a Question