Match complete field


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Match complete field
# 1  
Old 05-28-2014
Match complete field

hello,

i have a little problem, i want match the complete field ($1 or $2) with a complete word in another variable.

example:
i have a file with either one or two words per lane:
Code:
 
hsa-mir-4449 
hsa-mir-4707 
hsa-mir-4707* hsa-mir-4707
novelMiR_3551 novelMiR_3563
novelMiR_4330 novelMiR_1963
hsa-mir-625 
novelMiR_3660 hsa-mir-625
hsa-mir-4707* 
hsa-mir-4707 hsa-mir-4707*
novelMiR_440 novelMiR_1963
hsa-mir-470

and want search each word in the file with each line if this word is present.


my try to use match, i.e.
Code:
if (match($1,i) || match($2,i))

with $1,$2 both words per lane and i the complete lane, was not possible, because 'hsa-mir-470' also matches 'hsa-mir-4707'. how can i match only the complete field with complete words in the variable?

can i tell awk that only the complete $1 should match a complete word in i.
something like
Code:
/^$1$/ ~ i

or
Code:
match(\<$1\>,i)

- both not working...
# 2  
Old 05-28-2014
Not sure what you are after.. How about:
Code:
if ( $1==i || $2==i )

# 3  
Old 05-28-2014
no,

no, in i are both words, that means:

Code:
 
 hsa-mir-4707 == hsa-mir-4707* hsa-mir-4707

which is always false...

i want match the first word (which is a complete field) with a complete word in i...
# 4  
Old 05-28-2014
You could try:
Code:
split(i,F); for(j in F) if ( $1==F[j] || $2==F[j] )

This User Gave Thanks to Scrutinizer For This Post:
# 5  
Old 05-28-2014
thank you,

this should work - i'll try...
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 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

2. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

3. UNIX for Dummies Questions & Answers

Match pattern in a field, print pattern only instead of the entire field

Hi ! I have a tab-delimited file, file.tab: Column1 Column2 Column3 aaaaaaaaaa bbtomatoesbbbbbb cccccccccc ddddddddd eeeeappleseeeeeeeee ffffffffffffff ggggggggg hhhhhhtomatoeshhh iiiiiiiiiiiiiiii ... (18 Replies)
Discussion started by: lucasvs
18 Replies

4. Shell Programming and Scripting

Perl - Regular Expressions - Match complete word only

Hi Team, I have two strings like: xxx|yyy|Arizona Cardinals| Tell Cardinals | Cardinals bbb|Bell Earn, Jr | Bell Earn | Jayhawks | hawks I have a lookup file which has a set of strings. These need to be removed from above two strings Lookup file Contents: Bell Earn, Jr hawks... (2 Replies)
Discussion started by: forums123456
2 Replies

5. Shell Programming and Scripting

using field 2 in file2 to complete field 3 in file1

Hello, I was hoping someone could help me with this work related problem... basically what I want to do is the following: file2: 1 o 2 t 4 f 5 v 7 n 8 e 10 a file1: 1 : (8 Replies)
Discussion started by: smarones
8 Replies

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

7. Shell Programming and Scripting

awk to print field no 10 and complete event

hi, awk -F ";" '{if($10>500) then i++; } END{print i}' event_file_FR12_202_24-11-2009_* | less How to modify and add to this above to print the complete line in less ex : 4712714002021527;15298888;241129 095614... (1 Reply)
Discussion started by: madfox
1 Replies

8. Shell Programming and Scripting

first field match

Hi All, Thanks for your help in advance I am parsing a log file where the first field of each line can have the same key value but not more than 3 times in a row. Varying value of that first field changes as you go through the log but it either appears 3 times or two and sometimes only once.... (1 Reply)
Discussion started by: dragrid
1 Replies

9. Shell Programming and Scripting

match field between 2 files

I would like to do the following in bash shell. file a a:1 b:2 c:3 file b a:work:apple b:baby:banana c:candy:cat d:desk:dog I would like to match field 1 in file a to file b, if there's a match I would like to append field 2 in file a to field 3 in file b. Thank you. (8 Replies)
Discussion started by: phamp008
8 Replies

10. UNIX for Dummies Questions & Answers

seaching field and getting complete record

hi, I have a file..... 1|3|4|5|6 1|3|4|4|5 now i ahave to search for value 4 in forth field and write that output to a file. if i do grep 4 file1 both lines are coming to output. can somebody help me building command. thanks and regards sandeep (4 Replies)
Discussion started by: mahabunta
4 Replies
Login or Register to Ask a Question