Consolidate 2 file in 1 file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Consolidate 2 file in 1 file
# 1  
Old 12-24-2012
Consolidate 2 file in 1 file

Hi I have to file in with 1 similar colomn.
from both files i want similar values from column1 and col2 from file1 and col2 from file2 in file 3
file1
[CODE]colomn 1 colomn2
rmoved
[CODE]

Last edited by mirwasim; 01-17-2013 at 03:59 AM.. Reason: Code tags
# 2  
Old 12-24-2012
try

Code:
join file1 file2

Code:
awk 'NR==FNR{A[$1]=$0;next}{if(A[$1]){print A[$1],$2}}' file1 file2

# 3  
Old 12-24-2012
Its not working...
# 4  
Old 12-24-2012
Quote:
Originally Posted by mirwasim
Its not working...
What not working....?

Please look......
Code:
$ cat file1
8017172R 106126673.58
8017167R 139247928.99
2017917R 176606549.79
3514668R 277370594.03
2068764R 295968115.42
2515401R 420124600.33
7014281R 476346209.48
3012011R 526133734.06
2066522R 571615410.68

Code:
$ cat file2
8017172R 1061266735N
2015035R 1091944446N
8017167R 1392479289N
2017917R 1766065498N
6030741R 2052725599N
3514668R 2773705940N
2068764R 2959681154N
6030731R 3047202440N
2515401R 4201246003N
1006497R 4409300829N
6030777R 4435105434N
7014281R 4763462094N

Code:
$ awk 'NR==FNR{A[$1]=$0;next}{if(A[$1]){print A[$1],$2}}' file1 file2
8017172R 106126673.58 1061266735N
8017167R 139247928.99 1392479289N
2017917R 176606549.79 1766065498N
3514668R 277370594.03 2773705940N
2068764R 295968115.42 2959681154N
2515401R 420124600.33 4201246003N
7014281R 476346209.48 4763462094N

# 5  
Old 12-24-2012
please check this


tell me please where I am wrong

Last edited by mirwasim; 01-17-2013 at 03:59 AM.. Reason: Code tags
# 6  
Old 12-24-2012
SmilieSmilieSmilie

It should work.
don't know whats going on...Smilie

Have you tried using join ? Just remember files should be in sorted in order for using join.
# 7  
Old 12-24-2012
i m using kshell..should it be a problem?

---------- Post updated at 07:37 PM ---------- Previous update was at 07:35 PM ----------

Yes it is sorted using join i am getting only 1 row as out put

Code:
pin@ssdb0220[mir]$ join file11 file12
 1061266735N 126673.58

---------- Post updated at 08:14 PM ---------- Previous update was at 07:37 PM ----------

some one please help me to get it in some different form

Last edited by mirwasim; 01-17-2013 at 04:00 AM.. Reason: Please use code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Consolidate files based on priority

please help, I would like to merge 4 files, all of them same format. The first col is the key for all files,followed by variable number of fields so I want to check if the key is present in the files according to priority and then also add a column saying it came from which file . So the... (4 Replies)
Discussion started by: ritakadm
4 Replies

2. Shell Programming and Scripting

Consolidate several lines of a CSV file with firewall rules, in order to parse them easier?

Consolidate several lines of a CSV file with firewall rules Hi guys. I have a CSV file, which I created using an HTML export from a Check Point firewall policy. Each rule is represented as several lines, in some cases. That occurs when a rule has several address sources, destinations or... (4 Replies)
Discussion started by: starriol
4 Replies

3. Shell Programming and Scripting

Multiple lines consolidate

This post is start for me ... I stumped at something that I not sure as to how start on ... I tried so of your script that i honestly lost mind looking and looking here ... please help COL1 COl2 COL3 12222 AUH FLUEH 12222 SSC OPERA 12222 SSC ... (8 Replies)
Discussion started by: Sebastian.Thoma
8 Replies

4. Shell Programming and Scripting

Script to consolidate files as mails,groupid

Hi, I'm newbie in Bash scripting. Here is scenario I've a file which containslist of 100 mailgroup and in a directory i have 100 files with each group's respective mail addresses. I'd like to make one CSV file with this information as follows. consolidated files with mailid,groupname. ... (7 Replies)
Discussion started by: manish123456
7 Replies

5. Shell Programming and Scripting

Extract two file contents and consolidate in the third file

Hi all I have two files (first_file.txt) and ( second_file.txt). The first file consists of sentences line by line given as : Established in 1905 , Las Vegas officially became a city in 1911 . With the growth that followed , at the close of the century Las Vegas was the most populous... (10 Replies)
Discussion started by: my_Perl
10 Replies

6. Shell Programming and Scripting

How to consolidate values in one column from different rows into one?

Hi Guys, Thank you all for helping me with my different queries and I continue to get better at scripting because of help from all of you! I have a file that would look something like - ID SUB ID VALUE 1 10 5 2 18 7 1 ... (1 Reply)
Discussion started by: sncoupons
1 Replies

7. Shell Programming and Scripting

consolidate file in unix

hi, i am trying to consolodate the files in the unix with the '>>' i have some 50 or 60 files.is there any another way of consolidating the alll 50 or 60 files in to one file. actually the way i m doing creaating the problem while loading the file with teradat tpump and fasload. so if there is... (3 Replies)
Discussion started by: narang.mohit
3 Replies
Login or Register to Ask a Question