Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-03-2012
Registered User
 
Join Date: Oct 2011
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Awk pattern with letters and forward slash

Hi,

I have a tab delimited file "test.txt" like this:

Code:
id1 342 C/T
id2 7453 T/A/-/G/C
id3 531 T/C
id4 756 A/T/G
id5 23 A/G
id6 717 T/A/C
id7 718 C/T/A

And so on, with the possible choices for letters being A,C,T,G.
I would like to exclude from my file all the lines that do not have exactly any of the letters split by forward slash, followed by any of the letters. So I would like my file to look like this:


Code:
id1 342 C/T
id3 531 T/C
id5 23 A/G

I have not been able to find a good regex for this. I have tried:

Code:
awk '{  if($3 !='/([ACTG]\)/([ACTG]/)' {print}}'  test.txt

But it does not work, can you please tell me what I am doing wrong?
Thank you for your help.
-francy

Last edited by Scott; 03-03-2012 at 08:18 AM.. Reason: Please use code tags
Sponsored Links
    #2  
Old 03-03-2012
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Location: Zürich
Posts: 6,950
Thanks: 220
Thanked 760 Times in 664 Posts

Code:
$ awk '$3 ~ /^[ACTG]\/[ACTG]$/' file
id1 342 C/T
id3 531 T/C
id5 23 A/G

The Following User Says Thank You to Scott For This Useful Post:
francy.casa (03-03-2012)
Sponsored Links
    #3  
Old 03-03-2012
Registered User
 
Join Date: Oct 2011
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Thank you very much Scott! I was making it more complicated with useless curly brackets. Thanks!
    #4  
Old 03-03-2012
Scott's Avatar
Scott Scott is online now Forum Staff  
Administrator
 
Join Date: Jun 2009
Location: Zürich
Posts: 6,950
Thanks: 220
Thanked 760 Times in 664 Posts
You were close. The real difference is in using the match operator (~) instead of the equals operator (=).
The Following User Says Thank You to Scott For This Useful Post:
francy.casa (03-03-2012)
Sponsored Links
Closed Thread

Tags
awk, linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
AWK or SED to replace forward slash dshakey Shell Programming and Scripting 5 02-27-2012 10:29 PM
Replace Forward Slash with sed depakjan UNIX for Dummies Questions & Answers 19 09-29-2011 02:14 PM
Using sed to append backward slash before forward slash sarbjit Shell Programming and Scripting 2 10-15-2009 04:30 AM
escaping / (forward slash) farooqpervaiz Shell Programming and Scripting 1 08-07-2008 02:26 AM
Help with SED and forward slash gseyforth Shell Programming and Scripting 3 05-26-2008 07:29 AM



All times are GMT -4. The time now is 11:20 PM.