Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Look up Multiple files

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 10-15-2013
rramkrishnas rramkrishnas is offline
Registered User
 
Join Date: Oct 2013
Last Activity: 22 April 2015, 2:23 AM EDT
Posts: 18
Thanks: 4
Thanked 0 Times in 0 Posts
Signal Look up Multiple files

Hi,

Need help for matching column from three different files and find the mismatch details to new output file

my files below:
a.txt

Code:
column1,column2, column3
1,a,1-jan-13
2,b,3-jan-13
3,c,5-jan-13
4,d,12-dec-12
5,e,11-nov-11
6,f,1-oct-13

b.txt

Code:
1,a,1-jan-13
2,b,3-jan-13
3,c,5-jan-13
4,f,
5,f,11-nov-11
6,f,1-oct-13

c.txt

Code:
1,1-jan-13
2,3-jan-13
3,5-jan-13
4,12-dec-12
5,11-nov-11
6,1-oct-13

Output Required in below format.

Code:
a.column1a.column2a.column3b.column2b.column3c.column21a1-Jan-13a1-Jan-131-Jan-132b3-Jan-13b3-Jan-133-Jan-133c5-Jan-13c5-Jan-135-Jan-134d12-Dec-12f12-Dec-125e11-Novf11-Nov11-Nov6f1-Oct-13f1-Oct-131-Oct-13

I totaly new to Unix Shell Script, and don't know how to code for the above output.

Last edited by Franklin52; 10-15-2013 at 04:05 AM.. Reason: Please use code tags
Sponsored Links
    #2  
Old Unix and Linux 10-15-2013
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 10 April 2015, 1:52 AM EDT
Location: ./India/Bangalore
Posts: 1,231
Thanks: 57
Thanked 283 Times in 276 Posts
Please use code tag and provide desire o/p in proper format.
The Following User Says Thank You to pravin27 For This Useful Post:
rramkrishnas (10-16-2013)
Sponsored Links
    #3  
Old Unix and Linux 10-15-2013
rramkrishnas rramkrishnas is offline
Registered User
 
Join Date: Oct 2013
Last Activity: 22 April 2015, 2:23 AM EDT
Posts: 18
Thanks: 4
Thanked 0 Times in 0 Posts
Sorry for the unstructured sample output

Code:
a.txt
column1,column2, column3
1,a,1-jan-13
2,b,3-jan-13
3,c,5-jan-13
4,d,12-dec-12
5,e,11-nov-11
6,f,1-oct-13
 
b.txt
1,a,1-jan-13
2,b,3-jan-13
3,c,5-jan-13
4,f,
5,f,11-nov-11
6,f,1-oct-13

c.txt
1,1-jan-13
2,3-jan-13
3,5-jan-13
4,12-dec-12
5,11-nov-11
6,1-oct-13

Desired Output file can be in below format
 
a.column1,a.column2,a.column3,b.column2,b.column3,c.column2
1,a,1-Jan-13,a,1-Jan-13,1-Jan-13
2,b,3-Jan-13,b,3-Jan-13,3-Jan-13
3,c,5-Jan-13,c,5-Jan-13,5-Jan-13
4,d,12-Dec-12,f,,12-Dec-12
5,e,11-Nov-11,f,11-Nov-11,11-Nov-11
6,f,1-Oct-13,f,1-Oct-13,1-Oct-13

    #4  
Old Unix and Linux 10-15-2013
pravin27 pravin27 is offline Forum Advisor  
Advisor
 
Join Date: Sep 2009
Last Activity: 10 April 2015, 1:52 AM EDT
Location: ./India/Bangalore
Posts: 1,231
Thanks: 57
Thanked 283 Times in 276 Posts
try below code


Code:
awk -F"," 'NR==FNR{a[$1]=$0;next} a[$1] {a[$1]=a[$1]","$2","$3} END {for (i in a) { print a[i]}}' file1 file2 file3  | sed 's/,$//g' | sort -t"," -k1 -n

The Following User Says Thank You to pravin27 For This Useful Post:
rramkrishnas (10-16-2013)
Sponsored Links
    #5  
Old Unix and Linux 10-16-2013
rramkrishnas rramkrishnas is offline
Registered User
 
Join Date: Oct 2013
Last Activity: 22 April 2015, 2:23 AM EDT
Posts: 18
Thanks: 4
Thanked 0 Times in 0 Posts
Thanks Pravin, this has worked perfectly as per my requirement, however I was looking to get the column headings according to the file name, if you will see the output file format, I had given filename[.]column heading, can this be possible to print the same.

Code:
a.column1,a.column2,a.column3,b.column2,b.column3,c.column2

Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Run one script on multiple files and print out multiple files. grace_shen Shell Programming and Scripting 4 10-07-2013 12:08 PM
Run one script on multiple files and print out multiple files. grace_shen UNIX for Dummies Questions & Answers 0 10-07-2013 10:57 AM
Column extraction from multiple files to multiple files aozgaa Shell Programming and Scripting 5 10-18-2012 07:45 PM
awk, multiple files input and multiple files output gabrysfe Shell Programming and Scripting 5 05-29-2012 04:45 AM
Using AWK: Extract data from multiple files and output to multiple new files Liverpaul09 UNIX for Dummies Questions & Answers 3 10-12-2010 03:59 AM



All times are GMT -4. The time now is 07:31 PM.