Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 16th, 2012, 08:23 AM
manigrover manigrover is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 60 manigrover User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 42 m 3 sec
Reputation Power: 2
Match entires and seaprate by bracket before writing

Hi all,

I have a big file like this kind of data in two columns


Quote:
Code:
benzene blood disorders
nitrozen air disease



I have another file like this in different columns


Code:
Quote:
AXY benzene, nitrogen, oxygen, not available, sulfur
VTY nitrogen, notavailable, sulfur
I want from second columnonwards of second file it should match the first column of first file so that and if mathced right in fornt of it whatever is written.


Exoected output is


Quote:
Code:
AXY benzene (blood disorders), nitrogen (air disease), oxygen, not available, sulfur.
VTY nitrogen (air disease), notavailable, sulfur

Reply With Quote
  #2  
Old August 23rd, 2012, 05:13 PM
Axweildr's Avatar
Axweildr Axweildr is offline
'fie' on me, allege-dly
Click here for more information.
 
Join Date: Mar 2003
Location: in da kitchen ...
Posts: 12,874 Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)Axweildr User rank is General 81st Grade (Above 100000 Reputation Level)  Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1Folding Points: 162285 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Months 2 Weeks 1 Day 20 h 28 m 56 sec
Reputation Power: 6421
Send a message via Google Talk to Axweildr
Orkut
what do you expect to happen here?
__________________
--Ax
without exception, there is no rule ...
Handmade Irish Jewellery
Targeted Advertising Cookie Optout (TACO) extension for Firefox
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
-- Jamie Zawinski
Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
BIT COINS ANYONE

Reply With Quote
  #3  
Old August 24th, 2012, 12:45 AM
manigrover manigrover is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 60 manigrover User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 42 m 3 sec
Reputation Power: 2
Request to check

Hi

Thanks for reply.

I am looking for guidance regarding writing a perl program for such a question as I m novice in Perl programming as I am from Life science background and I need this for some science research.

Mani

Reply With Quote
  #4  
Old August 24th, 2012, 10:19 AM
FishMonger FishMonger is online now
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,645 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 21 h 16 m 17 sec
Reputation Power: 1170
Hello Mani,

We would be happy to help you with the troubleshooting of your code, however, based on your prior postings that I've read, you're looking for someone to write your entire script for you or at least the vast majority of it. If that's the case, then it would be best to hire a Perl programmer. If I'm wrong, then please post your script and a specific question on the part that is giving you trouble. Once we have that info, we can begin to give help.

Reply With Quote
  #5  
Old August 24th, 2012, 11:36 AM
FishMonger FishMonger is online now
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,645 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 21 h 16 m 17 sec
Reputation Power: 1170
I was needing a diversion from my own work, so I went ahead and worked up a minimal script for you.

Code:
use strict;
use warnings;

my $file1 = 'file1.txt';
my $file2 = 'file2.txt';

open my $f1_fh, '<', $file1 or die "failed to open $file1 $!";
open my $f2_fh, '<', $file2 or die "failed to open $file2 $!";

my %data;

while ( my $line = <$f1_fh> ) {
    chomp $line;
    my ($key, $value) = split /\s+/, $line, 2;
    $data{$key} = $value;
}
close $f1_fh;

while ( my $line = <$f2_fh> ) {
    chomp $line;
    my ($key, $value) = split /\s+/, $line, 2;
    my @parts = map { $data{$_} ? "$_ ($data{$_})" : $_ } split /, /, $value;
    
    printf "%s\t%s\n", $key, join(', ', @parts);
}
close $f2_fh;

Reply With Quote
  #6  
Old August 25th, 2012, 04:45 AM
manigrover manigrover is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 60 manigrover User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 42 m 3 sec
Reputation Power: 2
Request to check

Hi

Thanks for the reply.

I used this programm. May be I m doing soemthign worng with file 1 and file2 naming as I named my input files as file 1 and file 2 itself

or

May be I have to run the programm in differnet way

and it shows such errors as well.

Quote:
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65525.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65526.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65527.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65528.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65529.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65530.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65531.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65532.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65533.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65534.
Use of uninitialized value in hash element at pharmgkbtest.pl line 15, <$f1_fh> line 65535.

Reply With Quote
  #7  
Old August 25th, 2012, 08:12 AM
FishMonger FishMonger is online now
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,645 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 21 h 16 m 17 sec
Reputation Power: 1170
Obviously one or both of your data files is not formatted as you've presented to us.

Please post both of your scripts as attachments, not copy/pasted inline, so that we can see the precise format.

Reply With Quote
  #8  
Old August 25th, 2012, 10:22 AM
Laurent_R Laurent_R is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jun 2012
Posts: 502 Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level)Laurent_R User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 4 Days 18 h 50 m 40 sec
Reputation Power: 385
You probably have empty lines (or lines not having two fields) at the end of your file 1.

If this is the case, you can fix it by changing the relevant line:

Perl Code:
Original - Perl Code
  1. $data{$key} = $value if defined $value;

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Match entires and seaprate by bracket before writing

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap