LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Use of "Command line perl" in perl script using system command. (https://www.linuxquestions.org/questions/linux-newbie-8/use-of-command-line-perl-in-perl-script-using-system-command-770161/)

aditya007 11-19-2009 03:56 AM

Use of "Command line perl" in perl script using system command.
 
Hi,
I have not getting result, so I am describing my problem in deep.
=================================================================
MY QUERY :

>HUMAN1 ||elongation factor 2|HUMANA 43|||Manual
>HUMAN2 |||elongation factor 5|HUMANA 87|||Manual
>HUMAN3 |elongation factor 1|HUMANA 68|||Manual
.
.
.
.
AND SO ON...


I WANT :

elongation factor 2
elongation factor 5
elongation factor 1
=================================================================

MY PERL SCRIPT :

print "enter yr keyword \n";
$ok1=<stdin>;
chomp($ok1);

system("grep '^>' ".$ok1.".txt >".$ok1."_head.txt");

#[ NOTE :(Above system part is working for 'grep' command and i am getting result in
# ".$ok1."_head.txt"). ]

my $x=qw(perl -na -F'/\|+/' -e 'print "$F[1]\n"' ".$ok1."_head.txt" >".$ok1."6.txt");
system($x);

# [ NOTE : this will create a file ".$ok1."6.txt" But it is empty, it means that it
# is not working ]

Would anyone help me?

SethsdadtheLinuxer 11-19-2009 08:25 AM

Either "escape" the + sign or do it like this
`perl -na -F'/\|+/' -e 'print \"$F[1]\n\"' a1.txt >a2.txt"`
or
my $x=qw(perl -na -F'/\|+/' -e 'print \"$F[1]\n\"' a1.txt >a2.txt);
system($x);
or
system("perl -na -F'/\|\+/' -e 'print \"$F[1]\n\"' a1.txt >a2.txt");

aditya007 11-19-2009 11:39 PM

Reply to SethsdadtheLinuxer
 
Hi, SethsdadtheLinuxer

I have tried your 3 options, but I am not getting
answer, thats why I have described my QUERY in deep.

I think now you can understand it properly.

speck 11-20-2009 01:47 AM

I'm not sure exactly what you're trying to do, but if you want to extract the "elongation factor 2" type fields out of the ok1.txt file, then you could just use the split command (error trapping not included).
Code:

open INPUT, "ok1.txt";
while(<INPUT>) {
    chomp;

    if (/^>/) {
        my($j1, $good_field, $j2, $j3) = split(/\|+/);
        print "$good_field\n";
    }
}
close (INPUT);


aditya007 11-29-2009 10:08 PM

Reply to "speck"
 
Hi, speck

Thank you for your reply.

I am getting your point, but
I want to SOLVE THE PROBLEM
using command line option only.


You have given "\|+" option
for solution that I have used
in perl program, but Its not
working in "COMMAND LINE" option.

Regards,
Naman


All times are GMT -5. The time now is 05:51 PM.