我想用我的awk腳本獲得的值在Perl中創建一個數組。然後我可以在Perl中對它們進行數學運算。管道輸出從awk到perl
這裏是我的Perl,它運行一個程序,從而節省了一個文本文件:
my $unix_command_dsc = (`./program -s test.fasta saved_file.txt`);
my $dsc_run = qx($unix_command_dsc);
現在我有一些在awk,它分析的是保存在文本文件中的數據:
#!/usr/bin/awk -f
BEGIN{ # Initialize the values to zero. Note, done automatically also.
sumc4 = 0
sumc5 = 0
sumc6 = 0
}
/^[1-9][0-9]* residue/ {next} #Match line that begins with number and has word 'residue', skip it.
/^[1-9]/ { #Match line that begins with number.
sumc4 += $4 #Add up the values of the nth column into the variables.
sumc5 += $5
sumc6 += $6
print $4 "\t" $5 "\t" $6 #This will show the whole columns.
}
END{
print "sum H" "\t" "sum E" "\t" "sum C"
print sumc4 "\t" sumc5 "\t" sumc6
}
我從終端用下面的命令運行這個awk中:
./awk_program.txt saved_file.txt
任何想法我怎麼會從p收集該數據awk中的rint語句插入到perl中的數組中?
我已經試過是剛剛運行awk腳本在Perl:
my $unix_command_awk = (`./awk_program.txt saved_file.txt`);
my $awk_run = qx($unix_command_awk);
但perl的給我的錯誤,命令沒有找到,喜歡它認爲數據是命令。應該在awk中存在一個我缺少的STDOUT,而不是打印?
那豈不是更簡單,只是重新實現在Perl的邏輯。它將大致採用與awk代碼相同數量的代碼,並且您不需要調用外部進程並在之後解析結果。 – pmakholm
所以我仍然必須解析結果,即使我在awk中這樣做?是否有辦法在awk [value1,value2 ...]中創建一個列表,然後能夠在perl中使用該列表? – chimpsarehungry