Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-08-2011, 11:41 AM   #1
LQ Newbie
Registered: Feb 2011
Posts: 4

Rep: Reputation: 0
display awk output in perl


I am trying to use awk command in perl.

Below is my awk comamnd which works alone.

awk '{Easttot=Easttot+$1} END {print Easttot}' MessagesProcessedEAST2Cnts.dat

I would like to use this awk's output in shell script.

I am using system command like below to get the out put. But it is not working .

$Output = system("awk '{Easttot=Easttot+$1} END {print Easttot}' MessagesProcessedEAST2Cnts.dat'");

I am not sure if the above syntax is correct.
Please let me know.

Old 02-08-2011, 05:01 PM   #2
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917Reputation: 917
Hi, welcome to LQ!

How does the "not working" manifest itself?

Irrespective of "not working", you'd be better off to do
that calculation within perl rather than from an external
command - using two programming languages for one task
seems kind of inefficient.


Last edited by Tinkster; 02-08-2011 at 06:19 PM. Reason: meh
Old 02-08-2011, 07:59 PM   #3
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,852

Rep: Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111Reputation: 3111
I am with Tink on this one. Even though I am an avid awk user, it would seem a waste to use this when already using one of the most powerful string manipulative languages.
Old 02-08-2011, 08:24 PM   #4
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
From 'perldoc -f system':
The return value is the exit status of the program
Perhaps you meant to use `backticks`, or open().
But really, like the others have already said, the whole concept is just wrong and redundant. Calling AWK from Perl is like taking a hot-dog to a banquet.

--- rod.


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
awk does not > output Alkass Programming 4 04-25-2010 06:10 PM
How to redirect the output of exec command output in perl? sudhap85 Linux - Newbie 3 08-28-2009 04:35 PM
awk , I need help for awk, just a display function mcandy General 1 12-15-2008 01:21 PM
Awk Output kalyanofb Programming 4 02-02-2007 03:23 AM
Awk output Trouble fooforon Programming 6 04-12-2004 08:14 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:59 PM.

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