Bash: replace part of filename

前端 未结 3 367
温柔的废话
温柔的废话 2021-01-22 15:46

I have a command I want to run on all of the files of a folder, and the command\'s syntax looks like this:

tophat -o  


        
相关标签:
3条回答
  • 2021-01-22 16:19

    Alternative to anubhava's concise solution,

    d=$(dirname path/to/sample1.fastq)
    b=$(basename path/to/sample1.fastq .fastq)
    echo $d/$b.fastq
    path/to/sample1.fastq
    
    tophat -o "$d/$b.fastq" "$f"
    
    0 讨论(0)
  • 2021-01-22 16:31

    Not an answer but a suggestion: as a bioinformatician, you shoud use GNU make and its option -j (number of parallel jobs). The Makefile would be:

    .PHONY:all
    FASTQS=$(shell ls *.fastq)
    
    %.bam: %.fastq
        tophat -o $@ $<
    
    all:  $(FASTQS:.bam=.fastq)
    
    0 讨论(0)
  • 2021-01-22 16:33

    You can use:

    tophat -o "${f/.fastq/.bam}" "$f"
    

    Testing:

    f='path/to/sample1.fastq'
    echo "${f/.fastq/.bam}"
    path/to/sample1.bam
    
    0 讨论(0)
提交回复
热议问题