dbehera
asked on
merging two files using awk
Here's the problem.I have 2 files say file1 and file2.The format of the files are 10 segments(represent 1 customer information) repeating inself like
dus0101 customer number
dus0102 customer related information
dus0103 customer related information
... ...
... ...
dus0110 ...
dus0101 customer number
...
The customers in this 2 files are in asending order of customer account number.
Now i need to mearge these 2 files and create another file(say file3) depending on the customer number and the mearged file shud be in asending order of customer number.There might be same customer number in both files.If so skip that from file1 and write from file2 that customer to file3.The logic i can implement it as a c code but the requirement is to use shell script to arrive at this requirement.I can use awk script but i douth if nested awk can be used.Please let me know if you need anything else on this.Is there any other logic i can use
Thanks.
dus0101 customer number
dus0102 customer related information
dus0103 customer related information
... ...
... ...
dus0110 ...
dus0101 customer number
...
The customers in this 2 files are in asending order of customer account number.
Now i need to mearge these 2 files and create another file(say file3) depending on the customer number and the mearged file shud be in asending order of customer number.There might be same customer number in both files.If so skip that from file1 and write from file2 that customer to file3.The logic i can implement it as a c code but the requirement is to use shell script to arrive at this requirement.I can use awk script but i douth if nested awk can be used.Please let me know if you need anything else on this.Is there any other logic i can use
Thanks.
How about using perl? It's ideal for these kinds of tasks.
it sounds like it mught just be a sort|comm
ASKER
>>zsh script -- Gyles
Can you be more descriptive.I am not familiar with zsh.And i did not understand the logic u explained.
>>about using perl
Yea i can use perl and do it but i need to do it in shell programming.
Can you be more descriptive.I am not familiar with zsh.And i did not understand the logic u explained.
>>about using perl
Yea i can use perl and do it but i need to do it in shell programming.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have changed it to Perl and really Perl is so flexible in the things i want to do.It's quite easy.
Thanks
Thanks
You could do it with a zsh script (maybe other shells too?)
create script (see below) then call it with 2 file inputs.
script.zsh 3<file1 4<file2 >outputfile
In the script use your logic from above.
Use
read -u 3 file1line
read -u 4 file2line
to get lines from the 2 files. Then use
cut to get the customer numbers. Use if to compare, then do 9 more reads and prints on whichever file has the lower number.