Look up Multiple files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Look up Multiple files
# 1  
Old 10-15-2013
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 05:05 AM.. Reason: Please use code tags
# 2  
Old 10-15-2013
Please use code tag and provide desire o/p in proper format.
This User Gave Thanks to pravin27 For This Post:
# 3  
Old 10-15-2013
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 10-15-2013
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

This User Gave Thanks to pravin27 For This Post:
# 5  
Old 10-16-2013
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed parser behaving strange on replacing multiple words in multiple files

I have 4000 files like $cat clus_grp_seq10_g.phy 18 1002 anig_OJJ65951_1 ATGGTTTCGCAGCGTGATAGAGAATTGTTTAGGGATGATATTCGCTCGCGAGGAACGAAGCTCAATGCTGCCGAGCGCGAGAGTCTGCTAAGGCCATATCTGCCAGATCCGTCTGACCTTCCACGCAGGCCACTTCAGCGGCGCAAGAAGGTTCCTCG aver_OOF92921_1 ... (1 Reply)
Discussion started by: sammy777888
1 Replies

2. Shell Programming and Scripting

Removing carriage returns from multiple lines in multiple files of different number of columns

Hello Gurus, I have a multiple pipe separated files which have records going over multiple Lines. End of line separator is \n and records going over multiple lines have <CR> as separator. below is example from one file. 1|ABC DEF|100|10 2|PQ RS T|200|20 3| UVWXYZ|300|30 4| GHIJKL|400|40... (7 Replies)
Discussion started by: dJHa
7 Replies

3. Shell Programming and Scripting

Grep strings on multiple files and output to multiple files

Hi All, I want to use egrep on multiple files and the results should be output to multiple files. I am using the below code in my shell script(working in Ksh shell). However with this code I am not attaining the desired results. #!/bin/ksh ( a="/path/file1" b="path/file2" for file in... (4 Replies)
Discussion started by: am24
4 Replies

4. Shell Programming and Scripting

Create Multiple UNIX Files for Multiple SQL Rows output

Dear All, I am trying to write a Unix Script which fires a sql query. The output of the sql query gives multiple rows. Each row should be saved in a separate Unix File. The number of rows of sql output can be variable. I am able save all the rows in one file but in separate files. Any... (14 Replies)
Discussion started by: Rahul_Bhasin
14 Replies

5. Shell Programming and Scripting

Run one script on multiple files and print out multiple files.

How can I Run one script on multiple files and print out multiple files. FOR EXAMPLE i want to run script.pl on 100 files named 1.txt ....100.txt under same directory and print out corresponding file 1.gff ....100.gff.THANKS (4 Replies)
Discussion started by: grace_shen
4 Replies

6. UNIX for Dummies Questions & Answers

Run one script on multiple files and print out multiple files.

How can I run the following command on multiple files and print out the corresponding multiple files. perl script.pl genome.gff 1.txt > 1.gff However, there are multiples files of 1.txt, from 1----100.txt Thank you so much. No duplicate posting! Continue here. (0 Replies)
Discussion started by: grace_shen
0 Replies

7. Shell Programming and Scripting

Column extraction from multiple files to multiple files

I have roughly ~30 .txt files in a directory which all have unique names. These files all contain text arranged in columns separated by whitespace (example file: [#YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS TIDE #yr mo dy hr mn degT m/s m/s m sec ... (5 Replies)
Discussion started by: aozgaa
5 Replies

8. Shell Programming and Scripting

awk, multiple files input and multiple files output

Hi! I'm new in awk and I need some help. I have a folder with a lot of files and I need that awk do something in each file and print a new file with the output. The input file name should be modified when I print the outpu files. Thanks in advance for help! :-) ciao (5 Replies)
Discussion started by: gabrysfe
5 Replies

9. Programming

Control multiple program instances - open multiple files problem

Hello. This shouldn't be an unusual problem, but I cannot find anything about it at google or at other search machine. So, I've made an application using C++ and QtCreator. I 've made a new mime type for application's project files. My system (ubuntu 10.10), when I right click a file and I... (3 Replies)
Discussion started by: hakermania
3 Replies

10. UNIX for Dummies Questions & Answers

Using AWK: Extract data from multiple files and output to multiple new files

Hi, I'd like to process multiple files. For example: file1.txt file2.txt file3.txt Each file contains several lines of data. I want to extract a piece of data and output it to a new file. file1.txt ----> newfile1.txt file2.txt ----> newfile2.txt file3.txt ----> newfile3.txt Here is... (3 Replies)
Discussion started by: Liverpaul09
3 Replies
Login or Register to Ask a Question