0

I have the following command in a bash script:

$prefixBioAwk -c fastx '{ if(length($seq) > 600) { print ">"$name; print $seq }}' my.fasta > short.fasta

Now I want to make the number 600 flexible by inserting the var $myVar (which contains an iteger) there.

How do I do it?

5
  • 2
    If $prefixBioAwk is anything like Awk, awk -v variable="$value" 'length($seq) > variable { print ">" $name; print $seq }' my.fasta Commented Aug 31, 2016 at 12:06
  • 1
    Seems to be this one: github.com/lh3/bioawk Commented Aug 31, 2016 at 12:07
  • exactly, sorry, forgot to mention bioawk Commented Aug 31, 2016 at 12:09
  • hmmm... `-v' seems to have another function in bioawk. is there another way? Commented Aug 31, 2016 at 12:42
  • 1
    Looking at the github page, it seems -v serves same purpose as in awk Commented Aug 31, 2016 at 13:48

1 Answer 1

1

Since this is posted as a bash question, I'm answering with a bash response rather than something bioawk specific:

myVar=600 prefixBioAwk -c fastx '{ if(length($seq) > '$myVar') { print ">"$name; print $seq }}' my.fasta > short.fasta

The key is to get out of the single quotes so that the shell can interpret the variable and substitute its value.

Sign up to request clarification or add additional context in comments.

1 Comment

ups, surprisingly easy. I have to have a look at the logics of bash replacement, quotes, etc. Many thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.