LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-19-2009, 03:56 AM   #1
aditya007
LQ Newbie
 
Registered: Nov 2009
Posts: 5
Blog Entries: 1

Rep: Reputation: 0
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?

Last edited by aditya007; 11-19-2009 at 11:36 PM. Reason: I have edited my query, so now anyone can understand it easily
 
Old 11-19-2009, 08:25 AM   #2
SethsdadtheLinuxer
Member
 
Registered: Jun 2007
Posts: 152

Rep: Reputation: 37
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");
 
Old 11-19-2009, 11:39 PM   #3
aditya007
LQ Newbie
 
Registered: Nov 2009
Posts: 5

Original Poster
Blog Entries: 1

Rep: Reputation: 0
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.
 
Old 11-20-2009, 01:47 AM   #4
speck
Member
 
Registered: Nov 2001
Location: US
Distribution: Slackware 14.2
Posts: 375

Rep: Reputation: 115Reputation: 115
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);
 
Old 11-29-2009, 10:08 PM   #5
aditya007
LQ Newbie
 
Registered: Nov 2009
Posts: 5

Original Poster
Blog Entries: 1

Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl script system() only execute one command knockout_artist Programming 4 11-11-2008 10:57 AM
Perl Script works from command line, but not when evoked by Nagios gfem Linux - General 10 06-05-2008 03:59 PM
PERL script OK at command line, not in browser alvo Programming 4 12-19-2004 08:28 AM
Reconfigure command in "perl -MCPAN -e shell" asciimonster Linux - Software 1 09-16-2004 08:48 AM
Perl shell-out to script dunna work. Works on command line. Why? jlangelier Linux - Software 1 08-28-2004 02:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration