LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-23-2004, 07:14 PM   #1
amytys
LQ Newbie
 
Registered: Sep 2004
Posts: 11

Rep: Reputation: 0
Need to assign result of grep to var in PERL


I'm in PERL.

I've got a variable, say $x

I want to run a system call, say "grep -c mystring myfile", and assign the result of the grep back to $x.

When I say result of the grep, that would be what one would normally see in stdio... NOT the 0 (success) or errcode of the actual call to grep.

I've tried

$x = system("grep -c mystring myfile");

but that just gives me 0 (indicating no error with the call to grep) rather than my expected count (which in my case is 14).

How do I get the $x to contain the value 14, or whatever the grep would spit out to stdio?

Thanks!
 
Old 09-23-2004, 07:25 PM   #2
AAnarchYY
Member
 
Registered: Sep 2004
Location: Carlisle, MA
Distribution: Slackware 10.2 Fluxbox 2.6.17.6
Posts: 419

Rep: Reputation: 30
$x = `grep -c mystring myfile`;
 
  


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
Using find and grep - how to exclude a result ? graziano1968 Linux - General 13 12-04-2010 11:02 PM
ps -ef | grep iptables gives no result ? markraem Linux - Networking 1 07-07-2004 06:28 AM
how to grep within a script, and test result? bobbyr Programming 4 01-13-2004 01:11 PM
multiline grep result > multiple variable? mikshaw Linux - Software 5 12-25-2003 11:13 PM
ps -ef|grep -v root|grep apache<<result maelstrombob Linux - Newbie 1 09-24-2003 12:38 PM


All times are GMT -5. The time now is 03:32 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration