|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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.txtBut 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
|
||||
|
||||
|
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
|
|||
|
|||
|
Thank you very much Scott! I was making it more complicated with useless curly brackets. Thanks!
|
|
#4
|
||||
|
||||
|
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 | ||
|
![]() |
| Tags |
| awk, linux |
| Thread Tools | Search this Thread |
| 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 |
|
|