Question: Print (awk) and echo (bash) together to get variable in one row
gravatar for filipzembol
5.8 years ago by
filipzembol110 wrote:

Dear all, I create some pipe to get the information from the text file.

    for i in {0..249480000..60000}
    let "u +=60000"
    echo $i "-" $u
    samtools view /home/filip/Desktop/54321Odfiltrovany.bam  chrY:$i-$u | awk '{ n=length($10); print gsub(/[GCCgcs]/,"",$10)/n;}'| awk '{s+=$1}END{print NR,s/NR}'

OUTPUT what I want:

$i $u $NR $s/NR

for example:
0 60000 2 0.345
60000 120000 3 0.45

Could you help me. Because I do not know how could I join echo with print. Thank you.

bash awk join echo print • 6.1k views
ADD COMMENTlink modified 5.8 years ago by Istvan Albert ♦♦ 82k • written 5.8 years ago by filipzembol110
gravatar for Istvan Albert
5.8 years ago by
Istvan Albert ♦♦ 82k
University Park, USA
Istvan Albert ♦♦ 82k wrote:

Sometimes a strange battle can take place between shell and awk, where we want to allow some shell variables to pass into awk but we want to protect the awk variables from the shell.

The right solution is usually to rewrite your script to pass variables into awk with the -v flag like so:

$ export VALUE=100
​$ echo $HOME | awk -v shift=100 -v maxval=$VALUE  '{ print shift + maxval }'


ADD COMMENTlink modified 4 weeks ago by RamRS25k • written 5.8 years ago by Istvan Albert ♦♦ 82k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1131 users visited in the last hour