Match text in a range and copy value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match text in a range and copy value
# 1  
Old 10-29-2014
Match text in a range and copy value

In the files attached, I am trying to:

if Files.txt $1 is in the range of Exons.txt $1, then in Files.txt $4 the value from Exons.txt $3 is copied else if no match is found Exons.txt $3 = "Intron"

Code:
 For example, the first value in File.txt $1 is chr1:14895-14944 and is not found in any range of Exon.txt, so  File.txt row 1 looks like: chr1:14895-14944 A_16_P30000003 0.319605  intron.


Thanks Smilie.
# 2  
Old 10-29-2014
I not sure what you mean by "in the range of Exons.txt $1".... For example should chr1:14895-14944 (from line 1 of Files.txt) fall with the range of chr1:14111-15079 (from line 4 of exons.txt)?


This solution tries to do an exact match of $1 from files.txt with all $1 values in Exons.txt

Code:
awk 'FNR==NR { E[$1]=$3 ; next }
{ $4=$1 in E?E[$1]:"Intron" } 1' exons.txt files.txt

# 3  
Old 10-30-2014
Yes, you have it correct. I did not even see that match. Thank you Smilie.

For example should chr1:14895-14944 (from line 1 of Files.txt) fall with the range of chr1:14111-15079 (from line 4 of exons.txt)?

Thanks again.
# 4  
Old 10-30-2014
Can you give us a worked example as there appear to be some unspecified issues.

For example:

1) Is the value before the colon (eg chr1) used for anything? Does this need to match with the values in the exons.txt file?

2) The exons.txt file contains overlapping ranges eg:
Code:
chr1:16356-17015 WASH7P 660
chr1:16607-17305 WASH7P 699
chr1:16982-17618 WASH7P 637

what output would you expect for chr1:16999-17010 A_55_P12345678 0.22222
This User Gave Thanks to Chubler_XL For This Post:
# 5  
Old 10-30-2014
I noticied that to and don't have a good solution right now. I will mark the thread as solved a get a better example. Thank you very much 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 print text in field if match and range is met

In the awk below I am trying to match the value in $4 of file1 with the split value from $4 in file2. I store the value of $4 in file1 in A and the split value (using the _ for the split) in array. I then strore the value in $2 as min, the value in $3 as max, and the value in $1 as chr. If A is... (6 Replies)
Discussion started by: cmccabe
6 Replies

2. Shell Programming and Scripting

Get range out using sed or awk, only if given pattern match

Input: START OS:: UNIX Release: xxx Version: xxx END START OS:: LINUX Release: xxx Version: xxx END START OS:: Windows Release: xxx Version: xxx ENDHere i am trying to get all the information between START and END, only if i could match OS Type. I can get all the data between the... (3 Replies)
Discussion started by: Dharmaraja
3 Replies

3. Shell Programming and Scripting

Match and copy by text

In the attached .txt file, I am trying to match $5 with $1 and copy $4 to $7. That file was created using: awk 'BEGIN {OFS="\t"} {sub("chr","",$1)} {print $5,$2,$3,$1,$4,$7} {print $6,$3,$2,$1}' matrix_pxlence.txt > output.txt but I can not seem to add this last bit to the command. ... (1 Reply)
Discussion started by: cmccabe
1 Replies

4. Shell Programming and Scripting

Match to range in files

I am trying to create a script that will use the position in column A ($1) in 48850.txt and search for it in columns B ($2) in gene.txt. Then when it finds a match it copies the text in column A ($1) and places it in column C ($3) of 48850.txt. I have attached the files. Thank you :). The... (2 Replies)
Discussion started by: cmccabe
2 Replies

5. Shell Programming and Scripting

Match on a range of numbers

Hi, I'm trying to match a filename that could be called anything from vout001 to vout252 and was trying to do a small test but I'm not getting the result I thought I would.. Can some one tell me what I'm doing wrong? *****@********>echo $mynumber ... (4 Replies)
Discussion started by: Jazmania
4 Replies

6. Shell Programming and Scripting

Awk numeric range match only one digit?

Hello, I have a text file with lines that look like this: 1974 12 27 -0.72743 -1.0169 2 1.25029 1974 12 28 -0.4958 -0.72926 2 0.881839 1974 12 29 -0.26331 -0.53426 2 0.595623 1974 12 30 7.71432E-02 -0.71887 3 0.723001 1974 12 31 0.187789 -1.07114 3 1.08748 1975 1 1 0.349933 -1.02217... (2 Replies)
Discussion started by: meridionaljet
2 Replies

7. Shell Programming and Scripting

awk to match a numeric range specified by two columns

Hi Everyone, Here's a snippet of my data: File 1 = testRef2: A1BG - 13208 13284 AAA1 - 34758475 34873943 AAAS - 53701240 53715412File 2 = 42MLN.3.bedS2: 13208 13208 13360 13363 13484 13518 13518My awk script: awk 'NR == FNR{a=$1;next} {$1>=a}{$1<=a}{print... (5 Replies)
Discussion started by: heecha
5 Replies

8. Shell Programming and Scripting

Copy range of directory name

Hello folks hope all are doing well, i need to compress directories with range, i have total directories from 000-199 and i want to copy directories from 010 onwards to 020 meants total 11 directories, please suggest what regex will i use. Thanks, Bash (2 Replies)
Discussion started by: learnbash
2 Replies

9. Shell Programming and Scripting

match range of different numbers by AWK

if the column1 and 2 in both files has same key (for example "a" and "a1") compare each first key value(a1 of a) of input2 (for example 1-4 or 65-69 not 70-100 or 44-40 etc) with all the values in input1. if the range of first key value in input2 is outof range in input1 values named it as out... (54 Replies)
Discussion started by: repinementer
54 Replies

10. Shell Programming and Scripting

Match a specific IP range

Hello all, I would like a bit of help with a problem I am having. I have the following example file: $ cat test_hosts 10.10.2.3 host1 10.10.2.4 host2 10.10.2.130 host3 10.10.2.5 host4 10.10.2.230 host5 10.10.2.22 host6 I need to match all IP addresses in the 10.10.2.1-10.10.2.22... (5 Replies)
Discussion started by: sylaan
5 Replies
Login or Register to Ask a Question