awk move select fields to match file prefix in two directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk move select fields to match file prefix in two directories
# 1  
Old 01-14-2018
awk move select fields to match file prefix in two directories

In the awk below I am trying to use the file1 as a match to file2. In file2 the contents of $5,&6,and $7 (always tab-delimited) and are copied to the output under the header Quality metrics. The below executes but the output is empty. I have added comments to help and show my thinking. Thank you Smilie.

Code:
$5 = Total_Targets with value under it that can be a decimal or integer
$6 = Targets_less_than250x with value under it that can be a decimal or integer
$7 = Percent_more_than250x with value under it that can be a decimal or integer

file1 (123_Last-First_250x.txt)
Code:
Position    Gene    Type    Reads   Total_Targets   Targets_less_than250x   Percent_more_than250x
chr4:55141051   PDGFRA  NOCALL  13  2353    1   99.9575

file2 (123_Last-First_oca.txt)
Code:
Controls:
4 expression controls detected

desired output (123_Last-First_oncomine.txt)
Code:
Quality metrics:
Total_Targets   Targets_less_than250x   Percent_more_than250x
2353    1   99.9575
Controls:
4 expression controls detected

awk

portion in bold grabs $5,$6,$7 in file1 and stores it in array A and prints it in file2'
portion in teal adds the header to the output

Code:
awk 'FNR==NR{A[$5,$6,$7]=$0;next}$1 in A' OFS=\'t'  123_Last-First_250x.txt 123_Last-First_oca.txt | awk 'NR>1{print "Quality metrics:"}' > output


Last edited by cmccabe; 01-14-2018 at 10:30 AM.. Reason: fixed format
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash to update file on prefix match in two directories

I am trying to use bash to loop through a directory /path/to/data using a prefix match from /path/to/file. That match is obtained and works using the code below (in green)... what I can not seem to do is populate or update the corresponding prefix_file.txt in /path/to/data with the values in each... (3 Replies)
Discussion started by: cmccabe
3 Replies

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

3. Shell Programming and Scripting

awk to update file based on match in 3 fields

Trying to use awk to store the value of $5 in file1 in array x. That array x is then used to search $4 of file1 to find aa match (I use x to skip the header in file1). Since $4 can have multiple strings in it seperated by a , (comma), I split them and iterate througn each split looking for a match.... (2 Replies)
Discussion started by: cmccabe
2 Replies

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

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

6. Shell Programming and Scripting

awk to calculate fields only if match is found

Trying to combine the matching $5 values between file1 and file2. If a match is found then the last $6 value in the match and the sum of $7 are outputted to a new file. The awk below I hope is a good start. Thank you :). file1 chr12 9221325 9221448 chr12:9221325-9221448 A2M 1... (5 Replies)
Discussion started by: cmccabe
5 Replies

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

8. Shell Programming and Scripting

select lines with certain values on certain fields with awk

I need a awk command to select from a log-file only the lines that have on the 2nd field (considering "|" separator) one of the values 10.216.22.XX or 10.216.22.YY or 10.216.22.ZZ and on the 4th field only values that contain strictly digits. I want the command to work parsing the file only once (I... (2 Replies)
Discussion started by: black_fender
2 Replies

9. Shell Programming and Scripting

awk with fields select?

If i have a log file record.txt, with 10 fields - First field is datetime - 7th field is status - 8th filed is name - The last field (10th) is epoch time of the first field 02/17/2012 1:47 PM||||||In Use|chicken||1329515230 02/17/2012 2:53 PM||||||Available|chicken||1329519195 02/17/2012... (4 Replies)
Discussion started by: sabercats
4 Replies

10. Shell Programming and Scripting

printing select fields in awk

Hi, I want to print certain fields from my data file depending on certain conditions. Somebody pls let me know how to send it to awk. The command below is the one which I want to use in a shell script and this prints fine cat ./datafile.dat | grep -i $SEARCH_STR | awk -F: '{ print $1 $2 $3... (5 Replies)
Discussion started by: maverix
5 Replies
Login or Register to Ask a Question