![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
INDEL searches! | Bionewb | Bioinformatics | 5 | 02-26-2009 12:43 PM |
![]() |
|
Thread Tools |
![]() |
#1 |
Junior Member
Location: Ireland Join Date: Mar 2013
Posts: 5
|
![]()
Hello,
I've been at this problem for some time now and any adice would be great. I have a file as such: Peter..Bjorn,John..Mary,Paul..Simon,Jack..Steve, I wrote the following code: @array = $line =~ /([A-Za-z]+\.\.[A-Za-z]+\,[A-Za-z]+\.\.[A-Za-z]+)/g; It gives me: Peter,..Bjorn,John..Mary Paul..Simon,Jack..Steve What I really want it to give me is: Peter..Bjorn,John..Mary John..Mary,Paul..Simon Paul..SImon,Jack..Steve Is there anyway to go about doing that? I tried a lookaround, but that didn't help much. Thanks Last edited by anzdro; 07-18-2013 at 12:04 PM. |
![]() |
![]() |
![]() |
#2 |
Senior Member
Location: Boston area Join Date: Nov 2007
Posts: 747
|
![]()
More compact regex are more readable; use /gi; and you can drop the extra a-z (i=ignore case)
Could you check your examples for typos -- that regex should NOT be generating the output you specify (your code is missing the join command anyhow that you must be referring to). And is it you just want the 2nd name pair duplicated? It would help if you underlined what is different between intended and obtained. Also, please use the CODE formatting for your example & code -- much, MUCH easier to debug regex when in constant width font Last edited by krobison; 07-18-2013 at 01:37 PM. |
![]() |
![]() |
![]() |
#3 |
Registered Vendor
Location: Eugene, OR Join Date: May 2013
Posts: 521
|
![]()
You want it to print out the first comma delimited bit, then print out two copies of each of the following comma delimited bits with a space between the copies, then print out a single copy of the last bit? That sounds difficult with a one-liner
In Perl I would Code:
#!/usr/bin/perl $current_line = "Peter..Bjorn,John..Mary,Paul..Simon,Jack..Steve,"; @line = split(",",$current_line); print "$line[0],"; for ($x = 1; $x < (@line - 1); $x++) { print "$line[$x] $line[$x],"; } print "$line[$x]\n";
__________________
Providing nextRAD genotyping and PacBio sequencing services. http://snpsaurus.com |
![]() |
![]() |
![]() |
Thread Tools | |
|
|