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