Using c++ to analyze two file problem


 
Thread Tools Search this Thread
Top Forums Programming Using c++ to analyze two file problem
# 1  
Old 07-11-2011
Using c++ to analyze two file problem

Hi, I have two files:
Input_file1.txt
Code:
124
235
152
178
156
142
178
163
159

Input_file2.txt
Code:
124|5623
452|6698
178|9995
235|7542
159|8852
152|9963
156|8512
885|9956
754|6523

Desired_output.txt:
Code:
124|5623
235|7542
152|9963
178|9995
156|8512
142|
178|9995
163|
159|8852

Rules to follow when writing program:
[code]
1. The sequence of output file Should be in accordance to File 1. If any Value of File 1 is not found in File 2 then second field of Output file should be a blank.
2. Desired format in c program:
Code:
./c_program_name Input_file1.txt Input_file2.txt Desired_output.txt

Awk code that I have tried:
Code:
awk -F"|" ' NR == FNR { arr[$1]=$2; next } {  print $1"|"arr[$1] } '  Input_file2.txt Input_file1.txt > Desired_output.txt

The above awk code work fine for small data.
Unfortunately, it takes a long time for data more than 1Gb Smilie
Thanks for any advice.
# 2  
Old 07-13-2011
The first thing I'd do is sort the files, otherwise you have to scan the whole file2 for each line of file1. So you'd either do UNIX sort(1) and use that as input to your program, or you'd implement some sorting within the program.
Once sorted, you just have to search file2 until you hit a line that is greater than the current number from file1 to find out whether file2 contains that number or not.
This User Gave Thanks to mirni For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to analyze sosreport file that I generated.?

Hello Team, Could You give me some hints how I should review the sosreport that I generated? I know how to analysis the SAR files however sosreport is my last hope - python script has hunged and I would like to know the root cause - for this is not performance issue. Thanks in advance! ... (3 Replies)
Discussion started by: nsmcny
3 Replies

2. Solaris

Snapshot analyze

Hi, Is there any tool is available for analyzing Oracle X86 snapshot output. Thanks in advance. (1 Reply)
Discussion started by: sunnybee
1 Replies

3. UNIX for Dummies Questions & Answers

analyze lines in a file by loop

Hi Dears, I use the below code to analyze lines in a file: for line in `cat ucsv` do echo $line //analyze statements donehowever, if line contains space char, it will be broken. for example, if file content is: #login,full name,email,project,role,action gmwen,Bruce... (3 Replies)
Discussion started by: crest.boy
3 Replies

4. UNIX for Dummies Questions & Answers

How to analyze file hashing

What command should I use to analyze file hashing of fixed flat files. How much work does it take for multiple flat files. (3 Replies)
Discussion started by: jbjoat
3 Replies

5. Cybersecurity

How to analyze malicious code

A series on The H about analyzing potentially malicious code flying around on the net. Pretty well written, and a nice read for those interested in how exploits work: CSI:Internet - Alarm at the pizza service CSI:Internet - The image of death CSI:Internet - PDF timebomb CSI:Internet -... (0 Replies)
Discussion started by: pludi
0 Replies

6. Shell Programming and Scripting

Find and analyze variable Strings in a large file.

Hi guys, I have multiple files (>5000) which I have in a folder. I read every file name and put it in a tmp variable "i" so that i can use it in the following task. I have a large .txt file (>50 MB) in which I want to find the variable "i" and the lines after this variable, so that I can use... (4 Replies)
Discussion started by: Ashitaka007
4 Replies

7. Solaris

Analyze packets with snoop

Is there anywhere we can get details about what we should expect to see and not to see in some packets captured with "snoop" during troubleshooting a problem? I know we can capture packes for a failed transaction and compare them with packets for a successful trasaction.Is that the only way to... (4 Replies)
Discussion started by: Pouchie1
4 Replies

8. Solaris

How to analyze the outcome of patchdiag

Hi Gurus, I have installed the stuff needed for patchdiag for patching, its working okay , however after execution of pathcdiag.sparc i am unable to understand the summury which is produced at the end. Please help ! Thanks (3 Replies)
Discussion started by: kumarmani
3 Replies

9. Shell Programming and Scripting

Analyze Statistics

I have a file which contains records in the format of 2006-08-25 12:06:13|ABC|93 2006-08-25 12:45:55|ABC|203 2006-08-25 01:48:19|DEF|156 2006-08-25 01:49:09|ABC|12798 2006-08-25 02:49:59|GHL|4109 2006-08-25 03:50:50|DEF|234 where the format is "arrive time"|"message type"|"processing... (3 Replies)
Discussion started by: mpang_
3 Replies

10. Shell Programming and Scripting

Analyze the indexes and rebuild them

Hello UNIX and Oracle Gurus, After doing an intensive search from different websites, the UNIX forum I am posting this message seeking help.. I am trying to accomplish the following tasks through the shell script: 1. Rebuild indexes on a Table in Oracle 2. Analyze indexes and table... (0 Replies)
Discussion started by: madhunk
0 Replies
Login or Register to Ask a Question