Visit Our UNIX and Linux User Community


merge with awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting merge with awk
# 1  
Old 08-31-2009
merge with awk

Hi all,

I have got the following merge problem

file a

Code:
a 0001 something
a 0002 something
a 0003 something
a 0004 something

file b

Code:
b 0001 1111111111111
b 0002 2222222222222
b 0003 3333333333333
b 0004 4444444444444

File c should look like this
Code:
a 0001 something1111111111111

( it should grep awk '{print $2}' from file a)

grep the last word if 0001 matches and add it to the current line.

Thanks
for any awk sollutions

Last edited by vgersh99; 08-31-2009 at 11:44 AM.. Reason: code tags, PLEASE!
# 2  
Old 08-31-2009
Code:
nawk 'FNR==NR {a[$2]=$0;next} $2 in a {print a[$2] $3}' fileA fileB

# 3  
Old 08-31-2009
Thanks for that.
Is there any awk sollution to this as I am using busybox?
# 4  
Old 08-31-2009
Quote:
Originally Posted by stinkefisch
Thanks for that.
Is there any awk sollution to this as I am using busybox?
isn't the above an 'awk solution'?
# 5  
Old 08-31-2009
You already ask this question here and I provide you the answer here.

This is a duplicate thread, you should follow on https://www.unix.com/shell-programmin...ng-script.html

Thread reported, please read and understand the The UNIX and Linux Forums - Forum Rules
# 6  
Old 08-31-2009
Yes, it is, but I got the following problem now.

nawk
-bash: nawk: command not found

That's the reason why I ask for a awk solution
# 7  
Old 08-31-2009
the word 'nawk' sounds/look very similar to 'awk', doesn't it?
'nawk' is NEW awk.
Try the same code with 'awk'..........
And, please, do not multi-post!

Previous Thread | Next Thread
Test Your Knowledge in Computers #307
Difficulty: Easy
The common software-programming acronym 18N comes from the term Interlocalization;.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk merge two files

file1 AAA3:WWW1:DDD1:XXX8:DDD2:XXX9 AAA6:WWW2:FFF1:XXX130:FFF1:XXX104:FFF1:XXX16 AAA7:WWW3:ZZZ1:XXX4:ZZZ2:XXX5:ZZZ3:XXX6:ZZZ4:XXX7file2 XXX8:EEE1:EEE2 XXX9:KKK1:KKK2 XXX130:OOO1:OOO2 XXX104:PPP1:PPP2 XXX16:RRR1:RRR1 XXX4:UUU1:UUU2 XXX5:III1:III2 XXX7:JJJ1:JJJ2Result... (2 Replies)
Discussion started by: vikus
2 Replies

2. Shell Programming and Scripting

awk match and merge with 2 files

Dear Awk experts! I have been trying to get a one liner for a match and merge operation, but having difficulties as I'm an awk newb. I always get stuck on the match and merge with 2 files. I have 2 files as follows: File 1: field 1,field 2,field 3,field 4,field 5,field 6,field 7,field... (6 Replies)
Discussion started by: landossa
6 Replies

3. Shell Programming and Scripting

merge two files with awk

I have two file like follows. I want to merge them according the first field of file1. The separator of file1 is tab, while the second one is ",". I tried some code, but can't get the results. File1: AABB 6072 28 5922 BBCC 316 147 162 CCDD 907 71 231 File2: CCDD,hTRBV12-4,hTRBJ2-3,319895... (7 Replies)
Discussion started by: xshang
7 Replies

4. UNIX for Dummies Questions & Answers

file merge using awk

Hi All, I have 2 csv files. 1st file has 10 columns and the 2nd file has 12 columns. The requirement is, if the 4th column of file1 matches with the 4th column of file2, then append the 12th column of file2 with file1. Both files have equal number of lines and the 4th column values are... (1 Reply)
Discussion started by: ganesh_248
1 Replies

5. Shell Programming and Scripting

Another awk merge

File1 01C6,039E,RDF1+TDEV,120(2),1507_3RAID5,33 01C8,0E46,RDF1+TDEV,200(8),1507_3RAID5,33 01D4,045E,RDF1+TDEV,8,1507_3RAID5,33 01D5,045F,RDF1+TDEV,8,1507_3RAID5,33 File2 01C6,AA,BB,CC 01C8,,,NN 01D5,BB,KK, 0122,GG,, Ouput ... (2 Replies)
Discussion started by: greycells
2 Replies

6. Shell Programming and Scripting

AWK compare/merge

File1 2917,`0722,RDF1+TDEV,90(6),33,03E:0_12E:0,10000000c96c4af3_10000000c96c6e88,BL_db00p01e 2917,`0781,RDF1+TDEV,100(5),33,03E:0_12E:0,10000000c96c4af3_10000000c96c6e88,BL_db00p01e File2 2917,`0722,RDF1+TDEV,90(6),03E:0_12E:0,10000000c96c4af3_10000000c96c6e88,BL_db00p01e... (4 Replies)
Discussion started by: greycells
4 Replies

7. Shell Programming and Scripting

Merge files using AWK

I want to merge data from 2nd file to 1st file based on 1st column File1 ==== data1,12,comp1 data1,13,comp2 data3,14,, File2 ==== data1,11,host1,lit data2,11,host2,lit3 data3,11,host3,lit4 Required Ouput (5 Replies)
Discussion started by: greycells
5 Replies

8. Shell Programming and Scripting

Merge 2 csv files with awk

I have 2 files pipe delimted and want to merge them based on a key e.g file 1 123$aaa$yyy$zzz 345$xab$yzy$zyz 456$sss$ttt$foo 799$aaa$ggg$dee file 2 123$hhh 345$ddd 456$xxx 888$zzz so if the key is the first field, and the result should be the common key between file 1 and 2 (6 Replies)
Discussion started by: loloAix
6 Replies

9. Shell Programming and Scripting

two file merge with awk

Help I read a file that has 2 fields. look for in a second file the first field and update it with the second field of first file. file1 1131518fat11416.txt ../newaod/2001/04/2001-04-00129233-1.txt file2 INSERT INTO tabric VALUES... (2 Replies)
Discussion started by: mcarlo65
2 Replies

10. Shell Programming and Scripting

merge two files using awk

Hi Guys, I wonder whether is possible to merge two files using awk. I have two files one with 7 columns and another one with 9 columns and the first column on both files is identical so will be my key to merge the files. Any ideas.Thanks in advance. Harby. (2 Replies)
Discussion started by: hariza
2 Replies

Featured Tech Videos