user3534255
user3534255

Reputation: 147

syntax error unexpected token using pipe (|) in perl

I am making Perl script for know and I took so much time finding this kind of error in my script

 syntax error near unexpected token `|'
` | awk -F '/' '{print $11}''

And this is one line of my script where the error occur

awk -F \'=\' \'{print \$2}\' $bundle | awk -F \'/\' \'{print \$11}\'

this is what I have done. And the output of this is the name of the file i want.

Upvotes: 0

Views: 1119

Answers (1)

Tom Fenech
Tom Fenech

Reputation: 74655

In perl, use split rather than calling external commands:

(split '/', $bundle)[10];

Will return what you want.

Here's what I mean:

use strict;
use warnings;

my $bundle = "a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/";

print `echo $bundle | awk -F \'/\' \'{print \$11}\'`;
print ((split '/', $bundle)[10], "\n");

Both lines will output k.

But I'm confused, what are the double quotes around your command for?

Upvotes: 2

Related Questions