简体   繁体   中英

How to replace extension in bash regex?

I'm trying to write a bash script to calculate some biological stuff. I have a problem with regex, bash is a little unfamiliar to me yet. Unfortenly I have no time to learn it that fast coz I need immanently results. So my files:

RV30.afa
resFilesRV30.fasta
RV30213.afa
resFilesRV30213.fasta
RV30441.afa
resFilesRV30441.fasta
...

Command i have to use:

mscore -cftit RV30.afa resFilesRV30.fasta >FinalRV30.txt'

What i have now:

#!/bin/bash
parallel 'mscore -cftit {} resFile{}.fasta >final{.}.txt' ::: RV*.afa

The problem is: resFile{}.fasta = is trying to open file like this: resFileXXX. afa .fasta i need to skip extension in second argument (.afa) and ovewritte it by ".fasta".

I didn't find a piece of good advice on google for my problem (or i can't reforge it to my script yet), and my time to get results already ends. So i will be grateful for help in solving this problem. On its basis, I will be able to solve some of the others that appeared in my other scripts

This should work for you by substituting {} with {.} in 2nd argument:

parallel 'mscore -cftit {} resFiles{.}.fasta >final{.}.txt' ::: RV*.afa

As you're using already in your command, the replacement string {.} removes the extension.

这不起作用吗?

for afafile in *.afa; do number="${afafile#file}"; number="${number%.afa}"; ./mscore -cftit "$afafile" "resFile${number}.fasta" > "file${number}final.txt"; done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM