awk conditional operators- lookup value in 2nd file
I use conditional operators alot in AWK to print rows from large text files based on values in a certain column. For example:
In this case every row is printed from file1 to file2 for which the column 1 value in file1 is either A or C.
This is fine if I'm working with a few conditional values in column 1 (2 in the above example), however, if there are many values to look up, say 40, it becomes cumbersome to write out 40 conditional values. In this case it would be more efficient to place all those conditional values in a separate file say file3. For example, file 3 could look like:
File3
Basically I would like to print all file1 rows to file2 for which the column1 value in file1 is one of those listed in file3
File1
Desired output (file2) should look like:
Thanks in advance...
------ Post updated at 09:59 AM ------
I modified a code that I was using for something else, and it seems to work fine for printing columns1 and column2 of file1 to file2, however, I need the column3 value also printed.
Here is what I get (only 1st 2 columns are printed)
In the awk below I am splitting $7 on the : (colon) then - (hyphen) as array a. The word chr is printed at the start of every $1 line.
Next, $4 is split on the > (greater then) as array b. I am not sure how to account for the two other possibilities in $4 so the correct output is printed. Every... (3 Replies)
The bash bash below extracts the oldest folder from a directory and stores it in filename
That result will match a line in bold in input. In the matching line there is an_xxx digit in italics that
(once the leading zero is removed) will match a line in link. That is the lint to print in output.... (2 Replies)
I am trying to update the below awk, kindly provided by @RavinderSingh13, to update each line of file1 with either Low or No Low based on matching $2 of file1 to a range in $2 and $3 of file2. If the $2 value in file1 matches the range in file2 then that line is Low, otherwise it is No Low in the... (3 Replies)
In the below, I am trying to lookup $1 and $2 from file1, in a range search using $1 $2 $3 of file2. If the search key from file1 is found in file2, then the word low is printed in the last field of that line in the updated file1. Only the last section of file1 needs to be searched, but I am not... (6 Replies)
The below awk uses $3 and $4 in search as the min and max, then takes each $2 value in lookup and compares it. If the value in lookupfalls within the range in searchthen it prints the entire line in lookup/ICODE]. What I can't seem to figure out is how to print the matching $5 from search on that... (4 Replies)
have written a combined sed+awk to perform a lookup operation which works but looking to enhance it.
looking to match a record using any of the comma separated values + return selected fields from the record - including the field header. so:
cat foo
make,model,engine,trim,value... (6 Replies)
I have the below 2 files:
1) Third field from file1.txt should be compared to the first field of lookup.txt.
2) If match found then third field, file1.txt should be substituted with the second field from lookup.txt.
3)Else just print the line from file1.txt.
File1.txt:... (4 Replies)
I want to lookup filea with fileb,filec and filed.
If entry in filea exist in fileb and filec mark Y and then if entry in filea exist in filed mark as Y.
Final output should have all the entries from filea.
This prints only matching entries from file a in fileb i want all entries from... (9 Replies)
Write a quick shell snippet to find all of the IPV4 IP addresses
in any and all of the files under /var/lib/output/*, ignoring
whatever else may be in those files. Perform a reverse lookup on
each, and format the output neatly, like "IP=192.168.0.1,
... (0 Replies)
Hi All,
I have two files file1 and file2(lookup file).I need to map more than one keyfields of file1 with file2.how can we achieve it using awk.
file1(max 2.2 million records)
--------------------------
680720|680721|077
680720|680721|978
680721|680722|090
file2(no idea about the... (1 Reply)