This is a test version of Biostars. For the public version, visit https://www.biostars.org.
nested elements in bed file using awk

Hi everyone

I am using bedops solution given for the identification of nested elements from bed file at https://bedops.readthedocs.io/en/latest/content/reference/set-operations/nested-elements.html (mainly awk scripts)

and saved it as 1) script.awk ( and chmod 777 script.awk) 2) ./script.awk test.bed

which gives error of

/usr/bin/env: ‘awk -f’: No such file or directory

/usr/bin/env: use -[v]S to pass options in shebang lines

I tried all different options but can not fix this. I would appreciate all the suggestion.

coordinates bedops genome awk

Can you post the head of your script.awk file? Maybe something is wrong with your shebang (#!) line.

Here is script.awk

#!/usr/bin/env awk -f
{
    if (NR > 1) {
        currentChr = $1
        currentStart = $2
        currentStop = $3
        if ((previousStart < currentStart) && (previousStop > currentStop)) {
            print $0;
        }
        else {
            previousChr = currentChr
            previousStart = currentStart
            previousStop = currentStop
        }
    }
    else {
        previousChr = $1
        previousStart = $2
        previousStop = $3
    }
}

how about just awk -f /path/to/the/script.awk input.txt

1 answer

#!/usr/bin/awk -f or #!/usr/bin/env -S awk -f

will work

Log in to answer this question.