Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 29826  / 2 Years ago, mon, august 15, 2022, 9:14:16

My script is:



#!/usr/bin/perl -w

my $line="1 2 3 4 5 6 7";
print $line;
my $thirdlast=`print $line |awk '{print $(NF-3)}'`;
print $thirdlast;


The output is:



1 2 3 4 5 6 7   awk: 0602-542 There is an extra ) character.
The source line is 1.
The error context is
{print 201 1 >>> 201NF-3) <<<
Syntax Error The source line is 1.
awk: 0602-502 The statement cannot be correctly parsed. The source line is 1.
awk: 0602-542 There is an extra ) character.


What is it complaining about? Anything wrong with my script? Couldn't understand why it says The source line is 1.



What fix is needed by my script?


More From » perl

 Answers
7

You don't need to call awk inside your perl program, perl provides the necessary functions to perform such operation:



#!/usr/bin/perl -w

my $line="1 2 3 4 5 6 7";
my @tab = split(/s+/, $line);
print $tab[-3],"
";


This small program outputs: 5


[#25177] Wednesday, August 17, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
corsee

Total Points: 479
Total Questions: 122
Total Answers: 106

Location: Barbados
Member since Sat, May 9, 2020
4 Years ago
;