Print (awk) and echo (bash) together to get variable in one row
1
0
Entering edit mode
10.0 years ago
filipzembol ▴ 180

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.

awk join print echo bash • 8.9k views
ADD COMMENT
10
Entering edit mode
10.0 years ago

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 COMMENT

Login before adding your answer.

Traffic: 1789 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6