Depending on what fields you want to extract, you could do:
require(Rsamtools)
all.fields <- scanBam("0_sorted.bam")[[1]]
Running names(all.fields) should give you:
 [1] "qname"  "flag"   "rname"  "strand" "pos"    "qwidth" "mapq"   "cigar"
 [9] "mrnm"   "mpos"   "isize"  "seq"    "qual"  
You can then put any number of these into a *.tsv file, e.g.:
write.table(file="out.tsv", data.frame(all.fields[c("qname", "flag", "rname", "pos")]),
    quote=FALSE, sep="\t", row.names=FALSE)
Be aware that some of the fields may need coercion to a simpler data type, e.g., as.character(all.fields$seq). Also, if the file is large, you should look at restricting the number of fields you extract with the what argument in ScanBamParam; or, limiting yourself to extracting only one chromosome at a time with the which argument.
                    
                
                 
sir my problem is that i have .BAI file and i wants to convert this into TSV file format.
for this we need a python script and i have that python script.
now plz sir help me how to convert this file into tsv.
Like Aaron told you, this site is for R bioconductor support, not for analysis with Python or Bash. If you need help with your Python scripts or with Bash use other sites such as https://www.biostars.org/