Matching 10 Million file records with 10 Million in other file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Matching 10 Million file records with 10 Million in other file
# 8  
Old 06-13-2012
Here is a little bash script to generate 10million test records (for those wanting to test performance of their solutions):

make_test.bash
Code:
for((i=1;i<30000000;i++)) {
   printf -v id "%s%04d%04d%03d" $i $((RANDOM%10000)) $((RANDOM%10000)) $((RANDOM%1000))
   [ $RANDOM -lt 14000 ] && echo "20.04.2012 11.08.44;RECV;APPNAME@HOSTNAME06:$id;processed;Location;contact;status;email_id;2" >&2
   [ $RANDOM -lt 16384 ] && echo "APPNAME@HOSTNAME06:$id;SUCCESS" || echo "APPNAME@HOSTNAME06:$id;FAILURE"
}

Call it like this ./make_test.bash > Status.txt 2> Input.txt

Here is my solution:
Code:
awk -F'[:;]' '
NR==FNR{S[$2]=($3=="SUCCESS"); next}
{ if ($4 in S)
    print $1";"$2";"$3":"$4";"$5";"$6";"$7";"(S[$4]?"SUCCESS":"FAILURE")";"$8";"$9
  else
    print $0
}' Status.txt Input.txt > Result.txt

Will update this post when I know the runtime :-
Stack dump at record 20,127,745 (of 27,713,184) while reading Status.txt after 1m36s runtime

Seems like it's just too much data for my PC. Good news is it didn't seem to take very long to read in the data and there is hope for larger (64bit) servers.

Last edited by Chubler_XL; 06-13-2012 at 09:30 PM..
# 9  
Old 06-14-2012
Quote:
Originally Posted by Chubler_XL
Here is a little bash script to generate 10million test records (for those wanting to test performance of their solutions):

make_test.bash
Code:
for((i=1;i<30000000;i++)) {
   printf -v id "%s%04d%04d%03d" $i $((RANDOM%10000)) $((RANDOM%10000)) $((RANDOM%1000))
   [ $RANDOM -lt 14000 ] && echo "20.04.2012 11.08.44;RECV;APPNAME@HOSTNAME06:$id;processed;Location;contact;status;email_id;2" >&2
   [ $RANDOM -lt 16384 ] && echo "APPNAME@HOSTNAME06:$id;SUCCESS" || echo "APPNAME@HOSTNAME06:$id;FAILURE"
}

Well, I've tried my solution using just one big status file (splitting it in many files is actually a very bad idea that would lead to extremely long run times - days at least). So I used:

Code:
#!/bin/bash
IFS=";:"
for file in status.txt; do
   declare -a status
   while read -r x y z; do
     status[$y]=$z
     done < $file
  while read a b c d e f g h i l; do
     [[ ${status[$d]} = "" ]] || h=${status[$d]}
     printf '%s;%s;%s:%s;%s;%s;%s;%s;%s;%s\n' "$a" "$b" "$c" "$d" "$e" "$f" "$g" "$h" "$i" "$l" >> output.txt
     done  < input.txt
  unset status
  done
exit 0

It took about 2.7GB of ram to load the status array (so about two times the file size), the files were on a slow green disk and the CPU was clocked at 1.6GHz.

The script apparently works, but it's slow: 45 minutes.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Add 1 million columns

Hi, here is my problem: I've got a file with 6 columns (file1): a b c d e f a b c d e f a b c d e f a b c d e f I need to add 1 million columns to this file, each column needs to be a zero. Here is how the result file (file2) should look like (for the sake of the example, I've only... (7 Replies)
Discussion started by: zajtat
7 Replies

2. UNIX for Dummies Questions & Answers

Deleting a million of files ..

Hi, Which way is faster rm -rf /path/ or find / -name -exec rm {} \; and why? (7 Replies)
Discussion started by: cain82
7 Replies

3. UNIX for Dummies Questions & Answers

Pls. help with script to remove million files

Hi, one of the server, log directory was never cleaned up. We have so many files. I want to remove all the files that starts with dfr* but I get error message when I use the *. rm qfr* bash: /usr/bin/rm: Arg list too long I am trying to write this script but not working. ... (4 Replies)
Discussion started by: samnyc
4 Replies

4. Shell Programming and Scripting

Tail 86000 lines from 1.2 million line file?

I have a log file that is about 1.2 million lines long and about 300MB. we need a way to clean up this file and only keep the last few thousand lines. if i use tail command we run our of memory as the file is too big. I do have a key word to match on. example, we want to keep every line... (8 Replies)
Discussion started by: robsonde
8 Replies

5. What is on Your Mind?

Pick a Number Between 0 and 20 for 1 Million Bits

Here is an easy game! I wrote a number between 0 and 20 (that can include 0 and 20) on a piece of paper. I am staring at it now, imagining the number so you can read my mind ;) Reply once, and only once, with a number from 0 to 20 and the first person to guess it wins 1,000,000 Bits. ... (24 Replies)
Discussion started by: Neo
24 Replies

6. Shell Programming and Scripting

sort a file which has 3.7 million records

hi, I'm trying to sort a file which has 3.7 million records an gettign the following error...any help is appreciated... sort: Write error while merging. Thanks (6 Replies)
Discussion started by: greenworld
6 Replies

7. Shell Programming and Scripting

Extract data from large file 80+ million records

Hello, I have got one file with more than 120+ million records(35 GB in size). I have to extract some relevant data from file based on some parameter and generate other output file. What will be the besat and fastest way to extract the ne file. sample file format :--... (2 Replies)
Discussion started by: learner16s
2 Replies
Login or Register to Ask a Question