Match values in awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match values in awk
# 1  
Old 04-15-2015
Match values in awk

Having trouble modifying the below awk to match $1 of sample.txt to $1 of data.txt and if there is a match, then $2 of data.txt is copied to $7 of sample.txt. Thank you Smilie.

Code:
 awk 'NR==FNR{A[$1]=$1; next}  A[$1]  {$1=$1 " " A[$6]}1' data.txt sample.txt > output.txt

Code:
 
Desired Output:
Data Type:	ImaGene					
Sample Name	File	Cnt Channel	Probe Type	Factor:Gender	Factor:Control Gender	Classfn
1	./2523097xxxxx_1-31-2013/0_2523097xxxxx_Block1.txt	./2523097xxxxx_1-31-2013/1_2523097xxxxx_Block1.txt	Agilent 016267	Female	Male	Likely_Benign=>chr5:175511777-175710070; Likely_Benign=>chr6:78842630-79075754; Benign=>chr8:39199768-39409984; Benign=>chr14:45789786-46003777
2	./2523097xxxxx_1-31-2013/0_2523097xxxxx_Block2.txt	./2523097xxxxx_1-31-2013/1_2523097xxxxx_Block2.txt	Agilent 016267	Female	Male	Likely_Benign=>chr3:93794-142515

# 2  
Old 04-15-2015
Code:
awk 'NR==FNR{A[$1] ; next}  $1 in A { $7 = $2 }1' data.txt sample.txt > output.txt

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 04-15-2015
based on your explanation.....
Code:
awk 'NR==FNR{A[$1]=$2; next}  $1 in A{$7=A[$1]}1' data.txt sample.txt > output.txt


Last edited by vgersh99; 04-15-2015 at 01:41 PM..
This User Gave Thanks to vgersh99 For This Post:
# 4  
Old 04-15-2015
Thank you Smilie.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to match file1 and extract specific tag values

File2 is tab-delimeted and I am trying to use $2 in file1 (space delimeted) as a search term in file2. If it is found then the AF= in and the FDP= values from file2 are extracted and printed next to the file1 line. I commented the awk before I added the lines in bold the current output resulted. I... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

awk to print match or non-match and select fields/patterns for non-matches

In the awk below I am trying to output those lines that Match between file1 and file2, those Missing in file1, and those missing in file2. Using each $1,$2,$4,$5 value as a key to match on, that is if those 4 fields are found in both files the match, but if those 4 fields are not found then missing... (0 Replies)
Discussion started by: cmccabe
0 Replies

3. Shell Programming and Scripting

awk to update file based on partial match in field1 and exact match in field2

I am trying to create a cronjob that will run on startup that will look at a list.txt file to see if there is a later version of a database using database.txt as the source. The matching lines are written to output. $1 in database.txt will be in list.txt as a partial match. $2 of database.txt... (2 Replies)
Discussion started by: cmccabe
2 Replies

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

5. Shell Programming and Scripting

Using awk to match strings and outputing their corresponding values

Hi I will appreciate it if you can help me out. I have a file that contains this data System Load: 3244 card: 1903 CPU: 6% card: 1904 CPU: 6% card: 1905 CPU: 28% card: 1906 CPU: 28% card: 1907 CPU: 36% card: 1908 CPU: 37% I need to manipulate and output this as system_load:3244... (2 Replies)
Discussion started by: kaf3773
2 Replies

6. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

7. UNIX for Dummies Questions & Answers

awk display the match and 2 lines after the match is found.

Hello, can someone help me how to find a word and 2 lines after it and then send the output to another file. For example, here is myfile1.txt. I want to search for "Error" and 2 lines below it and send it to myfile2.txt I tried with grep -A but it's not supported on my system. I tried with awk,... (4 Replies)
Discussion started by: eurouno
4 Replies

8. Shell Programming and Scripting

match 2 files by values

Hello ALL, Hope all fine for you. I have the following task but no idea about how to do. I have 2 files (ascii) one of them is a list of bib records, looks like this: =LDR 01228nam 2200301 b 4500 =001 00000000000001 =005 20090429:10082000 =008 ... (2 Replies)
Discussion started by: ldiaz2106
2 Replies

9. Shell Programming and Scripting

Get values from different columns from file2 when match values of file1

Hi everyone, I have file1 and file2 comma separated both. file1 is: Header1,Header2,Header3,Header4,Header5,Header6,Header7,Header8,Header9,Header10 Code7,,,,,,,,, Code5,,,,,,,,, Code3,,,,,,,,, Code9,,,,,,,,, Code2,,,,,,,,,file2... (17 Replies)
Discussion started by: cgkmal
17 Replies

10. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies
Login or Register to Ask a Question