Sponsored Content
Top Forums Shell Programming and Scripting awk match and merge with 2 files Post 302871821 by Don Cragun on Thursday 7th of November 2013 03:27:25 AM
Old 11-07-2013
There is another inconsistency in the requested output:
Code:
field 1,field 2,field 3,field 4,field 5,field 6,field 7,field 8,field 9
1,first,yes,blah,1,a@b.com,m,12345,test 1,additional1
2,second,yes,this,1,b@c.com,n,22222,test 2,
3,third,no,that,1,a@example.com,n,44444,test 4,additional2
4,fourth,no,ok,1,b@example.com,f,57657,test 3

Note that a comma was added to the end of the line with 22222 in field 8, but no comma was added to the line with 57657 in field 8 (and neither of those values appear in field 1 in File 2).

If there is no match in File 2, should that input line be unchanged or should an empty field be added? And, should a new field have also been added to the header line in the output file?

Note that Yoda's script assumes that unmatched lines should not be changed and does not change the header line, while pravin27's script assumes an empty field should be added and adds a comma (but not a field name) to the header line.

Last edited by Don Cragun; 11-07-2013 at 04:32 AM.. Reason: Note differences between given scripts.
 

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

Merge files of differrent size with one field common in both files using awk

hi, i am facing a problem in merging two files using awk, the problem is as stated below, file1: A|B|C|D|E|F|G|H|I|1 M|N|O|P|Q|R|S|T|U|2 AA|BB|CC|DD|EE|FF|GG|HH|II|1 .... .... .... file2 : 1|Mn|op|qr (2 Replies)
Discussion started by: shashi1982
2 Replies

3. Shell Programming and Scripting

merge two files into one file use awk

Hi, guys. I have one question: I have two files: passwd and shadow (the number of records in these files are not equal)the contents of them are below: passwd: ************** ftp:x:24:24: sshd:x:71:65: uucp:x:10:14: brownj:x:5005:1000: sherrys: x :5006:1000: ... ************* ... (2 Replies)
Discussion started by: daikeyang
2 Replies

4. 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

5. 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

6. Shell Programming and Scripting

AWK to match and merge data from 2 files into 1.

Hello, hopefully this is an easy on for the AWK guru's out there. I'm having some trouble figuring out how to match+merge data in 2 files into 1 single report. I've got my 2 files filtered and delimited, just need to MATCH $3 in file1 to $1 in file2, then put $0 from File1 and $2+$3 from File2... (6 Replies)
Discussion started by: right_coaster
6 Replies

7. 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

8. 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

9. Shell Programming and Scripting

Merge columns from two files using awk

I have two csv files : say a.csv, b.csv a.csv looks like this : property1,property2,100 property3,property4,200 In a.csv, the combination of column1 and column2 will be unique b.csv looks like this property1,property2, 300, t1 property1,property2, 400,t2 property3, property4,800,t1... (2 Replies)
Discussion started by: Lakshmikumari
2 Replies

10. Shell Programming and Scripting

awk to match field between two files and use conditions on match

I am trying to look for $2 of file1 (skipping the header) in $2 of file2 (skipping the header) and if they match and the value in $10 is > 30 and $11 is > 49, then print the line from file1 to a output file. If no match is foung the line is not printed. Both the input and output are tab-delimited.... (3 Replies)
Discussion started by: cmccabe
3 Replies
form_field_opts(3CURSES)				     Curses Library Functions					  form_field_opts(3CURSES)

NAME
form_field_opts, set_field_opts, field_opts_on, field_opts_off, field_opts - forms field option routines SYNOPSIS
cc [ flag... ] file... -lform -lcurses [ library... ] #include <form.h> int set_field_opts(FIELD *field, OPTIONS opts); int set_field_opts(FIELD *field, OPTIONS opts); int field_opts_on(FIELD *field, OPTIONS opts); int field_opts_off(FIELD *field, OPTIONS opts); OPTIONS field_opts(FIELD *field); DESCRIPTION
set_field_opts() turns on the named options of field and turns off all remaining options. Options are boolean values that can be OR-ed together. field_opts_on() turns on the named options; no other options are changed. field_opts_off() turns off the named options; no other options are changed. field_opts() returns the options set for field. O_VISIBLE The field is displayed. O_ACTIVE The field is visited during processing. O_PUBLIC The field contents are displayed as data is entered. O_EDIT The field can be edited. O_WRAP Words not fitting on a line are wrapped to the next line. O_BLANK The whole field is cleared if a character is entered in the first position. O_AUTOSKIP Skip to the next field when the current field becomes full. O_NULLOK A blank field is considered valid. O_STATIC The field buffers are fixed in size. O_PASSOK Validate field only if modified by user. RETURN VALUES
set_field_opts, field_opts_on and field_opts_off return one of the following: E_OK The function returned successfully. E_SYSTEM_ERROR System error. E_CURRENT The field is the current field. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |MT-Level |Unsafe | +-----------------------------+-----------------------------+ SEE ALSO
curses(3CURSES), forms(3CURSES), attributes(5) NOTES
The header <form.h> automatically includes the headers <eti.h> and <curses.h>. SunOS 5.11 31 Dec 1996 form_field_opts(3CURSES)
All times are GMT -4. The time now is 10:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy