Finding strings


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding strings
# 1  
Old 12-10-2010
Finding strings

Hi I made a post earlier but now my problem has become a lot more complicated.

So I have a file that looks like this:

Code:
Name  1  13  94  1  AGGTT
Name  1  31  44  1  TTCCG
Name  1  13  94  2  AAAAATTTT
Name  1  41  47  2  GGGGGGGGGGG

So the file is tab delimited and what I want to do is find matches. First I want rows with AGGTT with a 1 at column 5, then I want to find rows with a 2 at column 5 but they have to match the initial row at column 2,3 and 4. If they match then the row will be put into another file.

so the output would look like this:

Code:
Name  1  13  94  2  AAAAATTTT

I hope I am clear here

thanks
# 2  
Old 12-10-2010
Code:
awk '($6=="AGGTT")&&($5==1){a=$2":"$3":"$4}($5==2)&&($2":"$3":"$4==a){print $0 > "another_file"}' ts1

Code:
$ cat ts1
Name  1  13  94  1  AGGTT
Name  1  31  44  1  TTCCG
Name  1  13  94  2  AAAAATTTT
Name  1  41  47  2  GGGGGGGGGGG

Code:
$ awk '($6=="AGGTT")&&($5==1){a=$2":"$3":"$4}($5==2)&&($2":"$3":"$4==a){print $0 > "another_file"}' ts1

Code:
$ cat another_file
Name 1 13 94 2 AAAAATTTT
$

# 3  
Old 12-10-2010
thanks

thanks but I got one issue... it does not print to the "another_file"
# 4  
Old 12-10-2010
What does it do instead?
# 5  
Old 12-10-2010
There is no file as the output
# 6  
Old 12-10-2010
if you are on Solaris, use nawk instead of awk

show us a copy paste of the command you've typed
# 7  
Old 12-10-2010
What features are you using that plain awk doesn't support?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding difference in between two array's of strings

Hi, Can anybody help me in finding the difference between two array elements with the help of code pls. purge=("Purge Concurrent Request and/or Manager Data" "Purge Signon Audit data" "Purge Obsolete Workflow Runtime Data" "Purge Logs and Closed System Alerts") purge_1=("Purge Obsolete... (3 Replies)
Discussion started by: Y.balakrishna
3 Replies

2. UNIX for Dummies Questions & Answers

Finding similar strings between two files

Hi, I have a file1 like this: ABAT ABCA1 ABCC1 ABCC5 ABCC8 ABCE1 ABHD2 ABL1 CAMTA1 ACBD3 ACCN1 And I have a second file like this: chr19 46118590 46119564 MACS_peak_1499 3100.00 chr19 46122009 46148405 CYP2B7P1 -2445 chr1 7430312 7430990... (7 Replies)
Discussion started by: a_bahreini
7 Replies

3. Shell Programming and Scripting

Finding Strings between 2 characters in a file

Hi All, Assuming i have got a file test.dat which has contains as follows: Unix = abc def fgt jug 111 2222 3333 Linux = gggg pppp qqq C# = ccc ffff llll I would like to traverse through the file, get the 1st occurance of "=" and then need to get the sting... (22 Replies)
Discussion started by: rtagarra
22 Replies

4. Shell Programming and Scripting

Finding strings through multiple lines

Hi, I need to search for a multiple line pattern and remove it the pattern is search for (ln number) <TABLE name=*> and if 3 lines below that the line is (ln number) </TABLE> Then remove those 4 lines. Thank you (14 Replies)
Discussion started by: legolad
14 Replies

5. Programming

finding and removing block of identical strings

i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings... for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies

6. Shell Programming and Scripting

finding and removing block of identical strings

i have a problem in finding block of identical strings...i solved the problem in finding consecutive identical words and now i want to expand the code in order to find and remove consecutive identical block of strings... for example the awk code removing consecutive identical word is:... (2 Replies)
Discussion started by: cocostaec
2 Replies

7. Shell Programming and Scripting

Finding number of strings in List

I have a list of strings stored in $Lst Example set Lst = "John Fred Kate Paul" I want to return 4 in this case. (1 Reply)
Discussion started by: kristinu
1 Replies

8. UNIX for Dummies Questions & Answers

Help with finding matching position on strings

I have a DNA file like below and I am able to write a short program which finds/not an input motif, but I dont understand how I can include in the code to report which position the motif was found. Example I want to find the first or all "GAT" motifs and want the program to report which position... (12 Replies)
Discussion started by: pawannoel
12 Replies

9. UNIX for Dummies Questions & Answers

Finding Unique strings which match pattern

I need to grep for a pattern in a file. Files are huge and have several repeated occurances of the strings which match pattern. I just need the strings which contain the pattern in the output. For eg. The contents of my file are as follows. The pattern I want to match by is ABCD ... (5 Replies)
Discussion started by: tektips
5 Replies

10. Shell Programming and Scripting

Finding character mismatch position in two strings

Hello, I would like to find an efficient way to compare a pair of strings that differ at one position, and return the difference and position. For example: String1 123456789 String2 123454789 returning something - position 6, 6/4 Thanks in advance, Mike (5 Replies)
Discussion started by: etherite
5 Replies
Login or Register to Ask a Question