LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 07-30-2011, 08:57 AM   #1
Alkass
Member
 
Registered: Mar 2010
Posts: 47

Rep: Reputation: 0
Executing a awk command inside perl script --


Hello experts

I want to execute a awk command, which reads from txt files and sums the numbers from the first column for those listed only inside a <init> block -- The awk command is like

Code:
awk '/<\/?init>/{x = !x}x{a++}x && a > 2{sum+=$1}END{printf"%E" "\n", sum}
So, I want to execute it inside a perl script, and execute the awk command for the infile which is also defined outside awk loop, ie doing something like


Code:
foreach $infile (@ARGV) {
  $gzin = gzopen($infile, "r") || die ("Couldn't open file $infile\n");

  # No. events and cross-section from current file
 my $xsec= `awk '/<\/?init>/{x = !x}x{a++}x && a > 2{sum+=$1}END{printf"%E" "\n", sum}' $infile`;
But this does not work and I get this

Code:
Use of uninitialized value in concatenation (.) or string at merge.pl line 54.
awk: /</?init>/{x = !x}x{a++}x && a > 2{sum+=}END{printf"%E" "
awk:           ^ unterminated regexp
awk: cmd. line:1: /</?init>/{x = !x}x{a++}x && a > 2{sum+=}END{printf"%E" "
awk: cmd. line:1:                                                          ^ unexpected newline or end of string
awk: cmd. line:1: ", sum}
awk: cmd. line:1: ^ unterminated string
Argument "" isn't numeric in numeric eq (==) at merge.pl line 98.
Any ideas ?
 
Old 07-30-2011, 10:33 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,516

Rep: Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893Reputation: 2893
Quote:
Any ideas ?
Why would you go to another string manipulating command when you are already inside one of the most powerful??

Perl is able to do everything (and of course a hell of a lot more) that is in your awk command.
 
  


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
Problem executing mv command inside shell script pablogosse Linux - General 7 12-16-2009 12:21 PM
linux command inside perl script von_vea Programming 5 09-08-2009 01:54 PM
How to Use AWK Command in Perl Script briana.paige Linux - Newbie 4 05-15-2009 11:48 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 04:11 PM
How to acess Variable defined in perl script inside an awk call sumin Programming 3 04-26-2007 05:19 AM

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

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