Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

paste and awk error inside perl script

Tags:

awk

perl

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

like image 833
sara Avatar asked Dec 12 '25 15:12

sara


1 Answers

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";
}
like image 61
Miller Avatar answered Dec 14 '25 08:12

Miller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!