I have 2 file. ACC_NUM contains only account numbers & ACC_DETAIL contains all information including account number seperated by ~ delimiter.
i am serching the account number in ACC_DETAIL from ACC_NUM. If it is exist, then copy all information in ACC_DETAIL_NEW file. For that i have written the following logic. It is working but taking too long time.
for i in 'cat ACC_NUM'
do
grep -w $i ACC_DETAIL > ACC_DETAIL_NEW
done
====
ACC Number is Alpha Numeric, which is a first column in the file. for exampple.
As grep will search entire file for each Account Number. It is taking time. Could comeone suggest other way to do effectively. ie by using AWK or JOIN. I have tried using JOIN, but i not expert in UNIX & no0t getting result.
Try using the join commd, first sort both the files on the field which is
common in both files.
so in your case the account number which is alpha numeric.
Thanks for your reply. It is working fine. But i also need to know some of the command option you have given below.
sort -d : is used to sort alpha-numeric filed. But also you have given +0 -1 option. What does it mean?
join -1 1 -2 1 -t~ a.num acc.num -o 2.1 2.2 2.3 2.4 > output : This coomand is working fine. But in file2, i have more than 4 column (ie 10 columns). If i do not write 2.1....2.4 or 2.10 will it work same? is there any other option where we can point out all column in file2 for join?
Please advise me so that i can understand it properly
Dear Amit,
The command : sort -d +0 -1 :-> it says to sort the input file on the field no
one (1) in directory order . The first field in your case is the key field and
that is alpha numeric hence we require to sort on directory order.
Secondly the number 2.1 2.2 2.3 etc are indicative of the field we require
in the output file.The same as per your requirement and you may alter to
suit your need.
Dear Amit
Just today only i came back .and read your feedback .To make join
cmmd successful the record length of the key record must be same
just check those three records and you will know where the fault is.
I hope I made the things clear.