Sponsored Content
Top Forums Shell Programming and Scripting awk to search field2 in file2 using range of fields file1 and using match to another field in file1 Post 302988175 by RavinderSingh13 on Wednesday 21st of December 2016 11:35:28 AM
Old 12-21-2016
Hello cmccabe,

I am not sure if I get your requirement completely so following code assumes that you want to match the contents according to Input_file2(means whatever and how many number of lines and fields in Input_file2 will be only matched to Input_fil1), also it checks condition where it checks values from Input_file1 should be greater than second field and lesser than 3rd field not vice versa.
Code:
awk 'FNR==NR{A[$1]=$0;B[$1,++D[$1]]=$2;next} {++C[$1]}($2<B[$1,C[$1]] && $3>B[$1,C[$1]]){print A[$1] FS $NF}'  Input_file2   Input_file1

You could make it tab delimited too, also if above assumption is not ok for you, kindly do let us know all the conditions and your query with complete details.

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

match value from file1 in file2

Hi, i've two files (file1, file2) i want to take value (in column1) and search in file2 if the they match print the value from file2. this is what i have so far. awk 'FILENAME=="file1"{ arr=$1 } FILENAME=="file2" {print $0} ' file1 file2 (2 Replies)
Discussion started by: myguess21
2 Replies

2. Shell Programming and Scripting

awk/sed search lines in file1 matching columns in file2

Hi All, as you can see I'm pretty new to this board. :D I'm struggling around with small script to search a few fields in another file. Basically I have file1 looking like this: 15:38:28 sz:10001 pr:14.16 15:38:28 sz:10002 pr:18.41 15:38:29 sz:10003 pr:19.28 15:38:30 sz:10004... (1 Reply)
Discussion started by: floripoint
1 Replies

3. Shell Programming and Scripting

Search & replace fields from file1 to file2

hi, I have two xml files with the name source.xml and tobe_replaced.xml. Sample data: source.xml contains: <?xml version="1.0"?> <product description="prod1" product_info="some/info"> <product description="prod2" product_info="xyz/allinfo"> <product description="abc/partialinfo"... (2 Replies)
Discussion started by: dragon.1431
2 Replies

4. Shell Programming and Scripting

AWK: Pattern match between 2 files, then compare a field in file1 as > or < field in file2

First, thanks for the help in previous posts... couldn't have gotten where I am now without it! So here is what I have, I use AWK to match $1 and $2 as 1 string in file1 to $1 and $2 as 1 string in file2. Now I'm wondering if I can extend this AWK command to incorporate the following: If $1... (4 Replies)
Discussion started by: right_coaster
4 Replies

5. Shell Programming and Scripting

Match one column of file1 with that of file2

Hi, I have file1 like this aaa ggg ddd vvv eeeand file2 aaa 2 aaa 443 xxx 76 aaa 34 ggg 33 wee 99 ggg 33 ddd 1 ddd 10 ddd 98 sds 23 (4 Replies)
Discussion started by: polsum
4 Replies

6. UNIX for Dummies Questions & Answers

if matching strings in file1 and file2, add column from file1 to file2

I have very limited coding skills but I'm wondering if someone could help me with this. There are many threads about matching strings in two files, but I have no idea how to add a column from one file to another based on a matching string. I'm looking to match column1 in file1 to the number... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

7. Shell Programming and Scripting

Retreive the records from file2 by using the first field in file1

Hi Freinds, i have a file1 as below file1 1|ndmf|fdd|d3484|34874 2|jdehf|wru7|478|w489 3|dfkj|wej|484|49894 file2 contains lakhs of records and not in sorted order i want to retrive only the records from file2 by searcing the first field of file 1 i used grep ^1 file2... (4 Replies)
Discussion started by: i150371485
4 Replies

8. UNIX for Dummies Questions & Answers

Compare file1 and file2, print matching lines in same order as file1

I want to print only the lines in file2 that match file1, in the same order as they appear in file 1 file1 file2 desired output: I'm getting the lines to match awk 'FNR==NR {a++}; FNR!=NR && a' file1 file2 but they are in sorted order, which is not what I want: Can anyone... (4 Replies)
Discussion started by: pathunkathunk
4 Replies

9. Shell Programming and Scripting

awk to update field in file2 if not the same as file1

Trying to use awk to: update $2 in file2 with the $2 value in file1, if $1 in file1 matches $13 in file2, which is tab-delimeted. The $2values may already be the same so in that case nothing happens and the next line is processed. There are exactly 4,605 unique $13 values. Thank you :). ... (4 Replies)
Discussion started by: cmccabe
4 Replies

10. Shell Programming and Scripting

awk to update field using matching value in file1 and substring in field in file2

In the awk below I am trying to set/update the value of $14 in file2 in bold, using the matching NM_ in $12 or $9 in file2 with the NM_ in $2 of file1. The lengths of $9 and $12 can be variable but what is consistent is the start pattern will always be NM_ and the end pattern is always ;... (2 Replies)
Discussion started by: cmccabe
2 Replies
KinoSearch1::QueryParser::QueryParser(3pm)		User Contributed Perl Documentation		KinoSearch1::QueryParser::QueryParser(3pm)

NAME
KinoSearch1::QueryParser::QueryParser - transform a string into a Query object SYNOPSIS
my $query_parser = KinoSearch1::QueryParser::QueryParser->new( analyzer => $analyzer, fields => [ 'bodytext' ], ); my $query = $query_parser->parse( $query_string ); my $hits = $searcher->search( query => $query ); DESCRIPTION
The QueryParser accepts search strings as input and produces Query objects, suitable for feeding into KinoSearch1::Searcher. Syntax The following constructs are recognized by QueryParser. o Boolean operators 'AND', 'OR', and 'AND NOT'. o Prepented +plus and -minus, indicating that the labeled entity should be either required or forbidden -- be it a single word, a phrase, or a parenthetical group. o Logical groups, delimited by parentheses. o Phrases, delimited by double quotes. o Field-specific terms, in the form of "fieldname:termtext". (The field specified by fieldname will be used instead of the QueryParser's default fields). A field can also be given to a logical group, in which case it is the same as if the field had been prepended onto every term in the group. For example: "foo:(bar baz)" is the same as "foo:bar foo:baz". METHODS
new my $query_parser = KinoSearch1::QueryParser::QueryParser->new( analyzer => $analyzer, # required fields => [ 'bodytext' ], # required default_boolop => 'AND', # default: 'OR' ); Constructor. Takes hash-style parameters: o analyzer - An object which subclasses KinoSearch1::Analysis::Analyzer. This must be identical to the Analyzer used at index-time, or the results won't match up. o fields - the names of the fields which will be searched against. Must be supplied as an arrayref. o default_field - deprecated. Use "fields" instead. o default_boolop - two possible values: 'AND' and 'OR'. The default is 'OR', which means: return documents which match any of the query terms. If you want only documents which match all of the query terms, set this to 'AND'. parse my $query = $query_parser->parse( $query_string ); Turn a query string into a Query object. Depending on the contents of the query string, the returned object could be any one of several subclasses of KinoSearch1::Search::Query. COPYRIGHT
Copyright 2005-2010 Marvin Humphrey LICENSE, DISCLAIMER, BUGS, etc. See KinoSearch1 version 1.00. perl v5.14.2 2011-11-15 KinoSearch1::QueryParser::QueryParser(3pm)
All times are GMT -4. The time now is 03:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy