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

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

    #!/bin/bash
    
    for i in {0..249480000..60000}
         do
    
    u=$i
    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}'
    
    done


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 • 5.1k views
ADD COMMENTlink modified 5.0 years ago by Istvan Albert ♦♦ 80k • written 5.0 years ago by filipzembol100
10
gravatar for Istvan Albert
5.0 years ago by
Istvan Albert ♦♦ 80k
University Park, USA
Istvan Albert ♦♦ 80k 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 }' 

​Produces

200

 

ADD COMMENTlink modified 5.0 years ago • written 5.0 years ago by Istvan Albert ♦♦ 80k
Please log in to add an answer.

Help
Access

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