#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    63
    Rep Power
    2

    Match the word and fetch the entries


    Match words and fetch data in front of it in second column
    Hi all,

    I have 2 files

    one file contain data like this in one column


    Code:
    AST3
    GSTY4
    JST3

    second file containign data like this in 2 columns



    Code:
    AST3(PAXXX),GSTY4(PAXXY) it is used in diabetes
    KST4 it is used in blood pressure
    JST3 it is never applied in oedema
    I have match column of first file with second file and if similarty of symbol which are made up of capital alphabets is there then it shuld copy the sentence in front of it

    The Expected out put is


    Code:
    AST3(PAXXX) it is used in diabetes
    GSTY4(PAXXY) it is used in diabetes
    JST3 it is never applied in oedema
    If it possible to remove the bracket then it will be good in expected output



    Code:
    AST3 it is used in diabetes
    GSTY4 it is used in diabetes
    JST3 it is never applied in oedema
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    779
    Rep Power
    495
    It seems that you have many of these types of things to do, and it also seems that you are not trying by yourself and just expect people on this forum to do your work for you.

    I am willing to help you to overcome difficulties, not to do everything in your place. Please show us what you have tried, and then we will be able to help you to progress.

    A solution for the last part (removing what is in the parentheses):

    Perl Code:
    my $line = "AST3(PAXXX) it is used in diabetes";
    $line =~ s/\([^)]+\)//;
    print $line, "\n"; # prints "AST3 it is used in diabetes"


    The regex looks for an opening paren, followed by as many characters other than a closing paren as possible, followed by a closing paren, and it replaces all this with nothing.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    63
    Rep Power
    2
    Hi

    Thanks for the reply

    I tried follwing programm but its not working properly as output is not there.Kindly check it.

    [QUOTE]
    PHP Code:
    use strict;
    use 
    warnings;

    my $file1 'pharmhkbdisease1.txt';
    my $file2 'phargkbdrug2.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;
        
    $line = ~ s/\([^)]+\)//;
        
    $data{$key} = $value;
        
    printf  $line"\n";
    }
    close $f2_fh
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    779
    Rep Power
    495
    Hello,

    as it is, your program will not even compile.

    This line:

    perl Code:
    my $file2 = 'phargkbdrug2.txt'

    needs a semi-colon (";") at the end.

    You are using the $key and $value variables for populating the %data hash without defining them.

    You probably want to change "printf" into "print".

    If you comment out the line where you try to populate the hash, these corrections should at least give you some output.

    Please also note that you are really using one of the two files, this is not sufficient for the result you want to accomplish.

IMN logo majestic logo threadwatch logo seochat tools logo