How can I agregate files with shell script

Compare three files: File1, File2, File3 and output to result_file.txt

From File1 fields $1, $2, $4, $5, $6 and $10 (fields contain letters and numbers, field separator "|")
From File2 fields $1, $2 and $5 (fields contain letters and numbers, field separator ",")
From File3 fields $1 and $2 (fields contain letters and numbers, field separator ",")

File1 is the reference file where I need to compare File2 and File3.

I need a script that will do:

If field $2 from File2 is equal to field $10 from File1 print fields $1, $2, $5, $4, $6 and $10 from File1 followed by field $5 and $1 from File2;

If field $1 from File3 is equal to field $4 from File1 print field $2 from File3 next to it, else print that field $2 with letter G, example: $1, $2, $5, $4, $2(equal letter or G), $6, $10, $5 and $1

If field $10 from File1 starts with letters "zm" then print "zzz", "xxx" and "yyy" on the last three fields, example: $1, $2, $5, $4, $2(equal letter or G), $6, $10(zzz), $5(xxx) and $1(yyy)

Output should be (with field separator "|": |$1|$2|$5|$4|$2|$6|$10|$5|$1|

Thanks
Dwebb33Asked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
paste -d, File1.txt File2.txt File3.txt  | awk -F' *[|,] *' 'BEGIN{OFS="|"}$17==$10{if($10~/^zm/){ $10= "zzz"; $20= "xxx";$16= "yyy";}if( $4 == $21){ $4 = $4 "|" $22; }print $1, $2, $5, $4, $6, $10, $20,$16}'

0
 
ozoCommented:
what if field $2 from File2 is equal to field $10 from File1 and field $1 from File3 is equal to field $4 from File1 and  field $10 from File1 starts with letters "zm" ?
On which line of File1, File2, File3 do you want to compare fields?
Do you want to search through File2 for any line with  field $2 equal to field $10 from File1?
Do you want to search through File3 for any line with field $1 equal to field $4 from File1?
0
 
ozoCommented:
what if field $2 from File2 is not equal to field $10 from File1 and field $1 from File3 is not equal to field $4 from File1 and  field $10 from File1 does not start with letters "zm" ?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
Dwebb33Author Commented:
Hi Ozo, thanks for your quick reply.

I want to compare line by line, starting with the first.

If field $2 from from File2 doesn't match field $10 from File1 don't print. If it matches then compare field $1 from File3 with field $4 from File1, if it matches print field $2 from File3 next to field $4 from File1, if it doesn't match print field $2 from File3 with value "G"

If all above is true and field $10 starts with"zm" then print "zzz", "xxx" and "yyy" on the last three fields ($10(zzz), $5(xxx) and $1(yyy) ).
0
 
Dwebb33Author Commented:
Hi Ozo, thanks for your quick reply.

I want to compare line by line, starting with the first.

If field $2 from from File2 doesn't match field $10 from File1 don't print. If it matches then compare field $1 from File3 with field $4 from File1, if it matches print field $2 from File3 next to field $4 from File1, if it doesn't match print field $2 from File3 with value "G"

If all above is true and field $10 starts with"zm" then print "zzz", "xxx" and "yyy" on the last three fields ($10(zzz), $5(xxx) and $1(yyy) ).
0
 
ozoCommented:

paste -d, File1 File2 File3  | awk -F'[|,]' 'BEGIN{OFS=","}$12==$10{if($10~/^zm/){ $10=$10 "zzz"; $15=$15 "xxx";$11=$11 "yyy";}print $1, $2, $5, $4,$14,$16,$4,$2 (($16==$4)?$17:"G"),$6,$10,$15,$11}'
0
 
Dwebb33Author Commented:
Sorry Ozo, but I received an awk error message.

I uploaded a doc file for better understanding.

I'm sorry if I'm not explaining myself.
example.docx
0
 
EE_AutoDeleterCommented:
I've requested that this question be deleted for the following reason:

No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Not enough information to confirm an answer.

If you feel this question should be closed differently, post an objection and a moderator will read all objections and then close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Auto Deleter
0
 
ozoCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.