문제

I used

paste Output1.txt Output2.txt | awk '{print $1, $2, $5, $15}' 

inside perl script by using system(awk_commamd). I am getting error like

awk: {print , , , }
awk:        ^ syntax error

Need help to sort this error

도움이 되었습니까?

해결책 2

It's because Perl is interpolating variables into your string, use single quotes instead:

system('paste Output1.txt Output2.txt | awk \'{print $1, $2, $5, $15}\'');

or:

system(q(paste Output1.txt Output2.txt | awk '{print $1, $2, $5, $15}'));

in any case, it is better to do this all in Perl without using system for increased performance, readability, and portability.

다른 팁

Duplicating the work of paste and awk using pure perl:

use strict;
use warnings;
use autodie;

my @fhs = map {open my $fh, '<', $_; $fh} qw(Output1.txt Output2.txt);

while (grep {!eof $_} @fhs) {
    my @lines = map {(scalar <$_>) // ''} @fhs;
    chomp @lines;
    my @fields = split ' ', join "\t", @lines;

    print join("\t", grep defined, @fields[0,1,4,14]), "\n";
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top