Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

match the second column and print rest of the column in horizontal form

by Anonymous Monk
on Sep 28, 2016 at 09:20 UTC ( [id://1172822]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a file data.txt having three columns. I want to print the rest of the column if the second column is same.
data.txt 1..1524 chromosomal replication initiator protein DnaA NC_017524 +.1 1..1524 chromosomal replication initiator protein DnaA NC_016768 +.1 1..1524 chromosomal replication initiator protein DnaA NC_009565 +.1 1000808..1002415 oxidoreductase NC_009565.1 1000808..1002415 oxidoreductase NC_017528.1 1002441..1002704 hypothetical protein NC_016934.1 1002812..1003792 peptidoglycan-binding protein ArfA NC_017523.1 1002812..1003792 peptidoglycan-binding protein ArfA NC_021194.1 1002812..1003792 peptidoglycan-binding protein ArfA NC_018143.2 1002812..1003792 peptidoglycan-binding protein ArfA NC_020089.1
I want the output as:
1..1524 chromosomal replication initiator protein DnaA NC_017524 +.1 NC_016768.1 NC_009565.1 1000808..1002415 oxidoreductase NC_009565.1 NC_017528.1 1002441..1002704 hypothetical protein NC_016934.1 1002812..1003792 peptidoglycan-binding protein ArfA NC_017523.1 + NC_021194.1 NC_018143.2 NC_020089.1
I will be thankful for any help

Replies are listed 'Best First'.
Re: match the second column and print rest of the column in horizontal form
by Corion (Patriarch) on Sep 28, 2016 at 09:23 UTC

    So what code have you already written and how does it fail to produce what you need?

Re: match the second column and print rest of the column in horizontal form
by tybalt89 (Monsignor) on Sep 28, 2016 at 13:31 UTC
    #!/usr/bin/perl # http://perlmonks.org/?node_id=1172822 use strict; use warnings; $_ = do { local $/; <DATA> }; 1 while s/^\S+ +(\S.*?\S) .*\K\n.*? \1(?= )//m; print; __DATA__ 1..1524 chromosomal replication initiator protein DnaA NC_017524 +.1 1..1524 chromosomal replication initiator protein DnaA NC_016768 +.1 1..1524 chromosomal replication initiator protein DnaA NC_009565 +.1 1000808..1002415 oxidoreductase NC_009565.1 1000808..1002415 oxidoreductase NC_017528.1 1002441..1002704 hypothetical protein NC_016934.1 1002812..1003792 peptidoglycan-binding protein ArfA NC_017523.1 1002812..1003792 peptidoglycan-binding protein ArfA NC_021194.1 1002812..1003792 peptidoglycan-binding protein ArfA NC_018143.2 1002812..1003792 peptidoglycan-binding protein ArfA NC_020089.1

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1172822]
Approved by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (9)
As of 2024-04-23 08:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found