Sponsored Content
Top Forums Shell Programming and Scripting Add fields in different files only if some fields between them match Post 302527844 by rdcwayx on Sunday 5th of June 2011 10:11:03 PM
Old 06-05-2011
So you'd like to replace col 3 & 4 in file2, if there is match in file1 with col 1&2?

Code:
awk 'NR==FNR{a[$1 FS $2]=$3;b[$1 FS $2]=$4;next} 
     {$3=(a[$1 FS $2]=="")?$3:a[$1 FS $2]; $4=(b[$1 FS $2]=="")?$4:b[$1 FS $2]}1' FS=, OFS=, file1 file2

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Match two files and divide fields

I have two files that have the date field in common. I request your help with some script that divide each field value from file1 by the correspond field value of the file2 only when the field date is equal in both files. Thanks in advance ! This is a sample of the files file 1 12/16/2010,... (2 Replies)
Discussion started by: csierra
2 Replies

2. UNIX for Dummies Questions & Answers

Match values from 2 files and append certain fields

Hi, I need help on appending certain field in my file1.txt based on matched patterns in file2.txt using awk or sed. The blue color need to match with one of the data in field $2 in file2.txt. If match, BEGIN and FINISHED value in red will have a new value from field $3 and $4 accordingly. ... (1 Reply)
Discussion started by: redse171
1 Replies

3. Shell Programming and Scripting

how to match fields from different files in PERL

Howdy! I have multiple files with tab-separated data: File1_filtered.txt gnl|Amel_4.0|Group3.29 1 G R 42 42 60 15 ,.AAA.aa,aa.A.. hh00/f//hD/h/hh gnl|Amel_4.0|Group3.29 2 C Y 36 36 60 5 T.,T, LggJh gnl|Amel_4.0|Group3.29 3 A R 27 27 60 9 Gg,,.gg., B6hcc22_c File2_filtered.txt ... (3 Replies)
Discussion started by: sramirez
3 Replies

4. Shell Programming and Scripting

awk help: Match data fields from 2 files & output results from both into 1 file

I need to take 2 input files and create 1 output based on matches from each file. I am looking to match field #1 in both files (Userid) and create an output file that will be a combination of fields from both file1 and file2 if there are any differences in the fields 2,3,4,5,or 6. Below is an... (5 Replies)
Discussion started by: ambroze
5 Replies

5. Shell Programming and Scripting

awk partial string match and add specific fields

Trying to combine strings that are a partial match to another in $1 (usually below it). If a match is found than the $2 value is added to the $2 value of the match and the $3 value is added to the $3 value of the match. I am not sure how to do this and need some expert help. Thank you :). file ... (2 Replies)
Discussion started by: cmccabe
2 Replies

6. Shell Programming and Scripting

awk to print fields that match using conditions and a default value for non-matching in two files

Trying to use awk to match the contents of each line in file1 with $5 in file2. Both files are tab-delimited and there may be a space or special character in the name being matched in file2, for example in file1 the name is BRCA1 but in file2 the name is BRCA 1 or in file1 name is BCR but in file2... (6 Replies)
Discussion started by: cmccabe
6 Replies

7. UNIX for Beginners Questions & Answers

Match Fields between two files, print portions of each file together when matched in ([g]awk)'

I've written an awk script to compare two fields in two different files and then print portions of each file on the same line when matched. It works reasonably well, but every now and again, I notice some errors and cannot seem to figure out what the issue may be and am turning to you for help. ... (2 Replies)
Discussion started by: jvoot
2 Replies

8. UNIX for Beginners Questions & Answers

awk match two fields in two files

Hi, I have two TEST files t.xyz and a.xyz which have three columns each. a.xyz have more rows than t.xyz. I will like to output rows at which $1 and $2 of t.xyz match $1 and $2 of a.xyz. Total number of output rows should be equal to that of t.xyz. It works fine, but when I apply it to large... (6 Replies)
Discussion started by: geomarine
6 Replies

9. Shell Programming and Scripting

Matching two fields in two csv files, create new file and append match

I am trying to parse two csv files and make a match in one column then print the entire file to a new file and append an additional column that gives description from the match to the new file. If a match is not made, I would like to add "NA" to the end of the file Command that Ive been using... (6 Replies)
Discussion started by: dis0wned
6 Replies

10. UNIX for Beginners Questions & Answers

Is there a UNIX command that can compare fields of files with differing number of fields?

Hi, Below are the sample files. x.txt is from an Excel file that is a list of users from Windows and y.txt is a list of database account. $ head -500 x.txt y.txt ==> x.txt <== TEST01 APP_USER_PROFILE USER03 APP_USER_PROFILE TEST02 APP_USER_EXP_PROFILE TEST04 APP_USER_PROFILE USER01 ... (3 Replies)
Discussion started by: newbie_01
3 Replies
PAGESIZES(5)                                                    File Formats Manual                                                   PAGESIZES(5)

NAME
pagesizes - HylaFAX page size definitions DESCRIPTION
The pagesizes database defines the page dimensions and guaranteed reproducible areas (GRA) for well-known page sizes. The GRA is the por- tion of the page that is guaranteed to be imaged during facsimile transmission. This region is typically less than the full page dimen- sions because of paper roller contacts and other mechanical aspects of the printing process in a facsimile machine. All HylaFAX programs that require page size information read the information from this database using a page size name. Documents should be prepared such that the full page dimensions are employed with the imaged area contained within the GRA. The system-wide default page size to use in preparing documents for transmission is given by the ``default'' entry in the database. (NB: the default entry should be placed last so that inverse matches find the real page size name and not the default entry.) The page size database is an ASCII file with the following format. Each entry consists of whitespace-separated fields: name abbrev width height gra-width gra-height top-margin left-margin Fields have the following interpretation: name the full name for the page size; e.g. ISO A4; abbrev an abbreviated version of the full name for use in compact listings such as the receive queue listing printed by faxstat(1); width the full width of the page; height the full height of the page; gra-width the width of the GRA; gra-height the height of the GRA; top-margin the margin between the top of the full page and the top of the GRA; left-margin the margin between the left side of the full page the left side of the GRA. The first two fields must be separated from the subsequent fields by a tab character (possibly followed by more whitespace); this is done to easily permit blank characters to be included in names. Otherwise fields can be separated by any amount of any kind of whitespace. Numbers are all base 10 and in basic measurement units (BMU); defined as 1/1200 x 25.4 millimeters for paper output with a scale factor of one. All fields must be present on a single line; otherwise the entry is ignored. Comments are introduced by the ``#'' character and con- tinue to the end the line. Page size database lookups are either by name or by page dimensions. Lookups by name are done by sequentially scanning the entries in the database for the first entry that has a matching abbreviation or substring of the page size name field. The string comparisons ignore case so, for example, ``a4'' would match a full name of ``ISO A4''. Lookups by dimension scan the entire database and return the page with the closest dimensions using a straightforward distance metric. If the difference in dimensions of the closest match is greater than 1/2 inch on each side, then no page entry is returned for a lookup by dimension. SEE ALSO
hylafax-client(1), faxmail(1), faxstat(1), sendfax(1), sgi2fax(1), textfmt(1). December 5, 1994 PAGESIZES(5)
All times are GMT -4. The time now is 01:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy