Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Matching fields between two files, repeated records Post 303010880 by RudiC on Tuesday 9th of January 2018 08:22:28 AM
Old 01-09-2018
Except for the formatting, how far would this get you:
Code:
awk '
NR == FNR       {q = $1 "," $2
                 $1 = $2 = ""
                 T[q "," ++C[q]] = $0
                 next
                }
                {q = $1 "," $3
                 X = q "," ++D[q]
                 printf "%s\t",  $0
                 if (X in T)    print T[X]
                 if ($3 == "?") print "  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -"
                }
' file1 file2

Please note, that
Quote:
awk's behavior is to give precedence to the last line number in an array when one of its elements is repeated
does not quite accurately describe the situation - array elements are just overwritten when indices are encountered another time(s), and awk does this as any other programming language.
This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

AWK Matching Fields and Combining Files

Hello! I am writing a program to run through two large lists of data (~300,000 rows), find where rows in one file match another, and combine them based on matching fields. Due to the large file sizes, I'm guessing AWK will be the most efficient way to do this. Overall, the input and output I'm... (5 Replies)
Discussion started by: Michelangelo
5 Replies

2. Shell Programming and Scripting

Averaging all fields while counting repeated records

Hi every one; I have a 31500-line text file upon which two following tasks are to be performed: 1: Rearranging the file 2: Taking the average of each column (considering number of zeros) and output the result into a new file This is the code I've come up with: awk '(NR%3150<3150)... (0 Replies)
Discussion started by: nxp
0 Replies

3. Shell Programming and Scripting

Creating a file with matching records from two other files

Hi All, I have 2 files (file1 & file2). File1 and File2 have m and n columns respectively I have to compare value in column1 of file1 with file2 and find line(s) from file2 matching column1 value. The value can be in any column in the matching lines of file2. The output should be... (10 Replies)
Discussion started by: Swagi
10 Replies

4. Shell Programming and Scripting

comparing two files for matching fields

I am newbie to unix and would please like some help to solve the task below I have two files, file_a.text and file_b.text that I want to evaluate. file_a.text 1698.74 1711.88 6576.25 899.41 3205.63 4187.98 697.35 1551.83 ... (3 Replies)
Discussion started by: gameli
3 Replies

5. Shell Programming and Scripting

Matching multiple fields from two files and then some?

Hi, I am working with two tab-delimited files with multiple columns, formatted as follows: File 1: >chrom 1 100 A G 20 …(10 columns) >chrom 1 104 G C 18 …(10 columns) >chrom 2 28 T C ... (4 Replies)
Discussion started by: mbp
4 Replies

6. Shell Programming and Scripting

How to merge two or more fields from two different files where there is non matching column?

Hi, Please excuse for often requesting queries and making R&D, I am trying to work out a possibility where i have two files field separated by pipe and another file containing only one field where there is no matching columns, Could you please advise how to merge two files. $more... (3 Replies)
Discussion started by: karthikram
3 Replies

7. Shell Programming and Scripting

Print matching fields (if they exist) from two text files

Hi everyone, Given two files (test1 and test2) with the following contents: test1: 80263760,I71 80267369,M44 80274628,L77 80276793,I32 80277390,K05 80277391,I06 80279206,I43 80279859,K37 80279866,K35 80279867,J16 80280346,I14and test2: 80263760,PT18 80279867,PT01I need to do some... (3 Replies)
Discussion started by: gacanepa
3 Replies

8. UNIX for Beginners Questions & Answers

Awk: matching multiple fields between 2 files

Hi, I have 2 tab-delimited input files as follows. file1.tab: green A apple red B apple file2.tab: apple - A;Z Objective: Return $1 of file1 if, . $1 of file2 matches $3 of file1 and, . any single element (separated by ";") in $3 of file2 is present in $2 of file1 In order to... (3 Replies)
Discussion started by: beca123456
3 Replies

9. Shell Programming and Scripting

Comparing two files by two matching fields

Long time listener first time poster. Hope someone can advise. I have two files, 1000+ lines in each, two fields in each file. After performing a sort, what is the best way to find exact matches where field $1 and $2 in file1 are also present in file2 on the same line, then output only those... (6 Replies)
Discussion started by: bstaff
6 Replies

10. UNIX for Beginners Questions & Answers

awk for matching fields between files with repeated records

Hello all, I am having trouble with what should be an easy task, but seem to be missing something fundamental. I have two files, with File 1 consisting of a single field of many thousands of records. I also have File 2 with two fields and many thousands of records. My goal is that when $1 of... (2 Replies)
Discussion started by: jvoot
2 Replies
rlm_passwd(5)							 FreeRADIUS Module						     rlm_passwd(5)

NAME
rlm_passwd - FreeRADIUS Module DESCRIPTION
The rlm_passwd module provides authorization via files similar in format to /etc/passwd. The lm_passwd module allows you to retrieve any account information from any files with passwd-like format (/etc/passwd, /etc/group, smb- passwd, .htpasswd, etc). Every field of the file may be mapped to a RADIUS attribute, with one of the fields used as a key. The module reads the file when it initializes, and caches the data in memory. As a result, it does not support dynamic updates of the files (the server has to be HUP'd), but it is very fast, even for files with thousands of lines. The configuration item(s): filename The path to the file. delimiter = ":" The character to use as a delimiter between fields. The default is ":" hashsize The size of the hashtable. If 0, then the passwords are not cached and the passwd file is parsed for every request. We do not rec- ommend such a configuration. A larger hashsize means less probability of collision and faster search in hashtable. Having a hash- size in the range of 30-100% of the number of passwd file records is reasonable. allowmultiplekeys If set to 'yes', and more than one record in file matches the request, then the attributes from all records will be used. If set to 'no' (the default) the module will warn about duplicated records. ignorenislike If set to 'yes', then all records from the file beginning with the '+' sign will be ignored. The default is 'no'. format The format of the fields in the file, given as an example line from the file, with the content of the fields as the RADIUS attributes which the fields map to. The fields are seperated by the ':' character. The key field is signified by being preceded with a '*' character, which indicates that the field has only one key, like the /etc/passwd file. The key field may instead be preceded with '*,', which indicates that the field has multiple possible keys, like the /etc/group file. The other fields signify RADIUS attributes which, by default, are added to the configuration items for a request. To add an attribute to the request (as though it was sent by the NAS), prefix the attribute name in the "format" string with the '~' char- acter. To add an attribute to the reply (to be sent back to the NAS) prefix the attribute name in the "format" string with the '=' character. ignoreempty This configuration item defaults to "yes". If there is no value for the attribute, then the attribute is not added. By setting this value to "no", you can force the attribute to be added, even if there is no value. EXAMPLES
format = "My-Group:::*,User-Name" Parse a file similar to the /etc/group file. An entry matches a request when the name in a User-Name attribute exists in the comma- seperated list of a line in the file. When an entry matches, a "My-Group" attribute will be created and added to the configuration items for the request. The value of that attribute will be taken from the first field of the matching line in the file. The ":::" in the format string means that there are extra two fields in the line, in between the group name and list of user names. Those fields do not map to any RADIUS attribute, and are therefore ignored. For this example to work in practice, you will have to add the My-Group attribute to the dictionary file. See the dictionary manual page for details on how this may be done. format = "~My-Group:::*,User-Name" Similar to the previous entry, except the My-Group attribute is added to the request, as though it was sent by the NAS. SECTIONS
authorize FILES
/etc/raddb/radiusd.conf SEE ALSO
radiusd(8), radiusd.conf(5) dictionary(5), AUTHOR
Alan DeKok <aland@freeradius.org> 14 April 2004 rlm_passwd(5)
All times are GMT -4. The time now is 10:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy