I am trying to extract parts of a filename, where I want to extract everything after the first _ and I have found a working solution, see below
file=22NGS71294_S191_R1_001.fastq.gz
echo $file
22NGS71294_S191_R1_001.fastq.gz
echo ${file#*[_ ]}
S191_R1_001.fastq.gz
but, when I use wildcards, it stops working
file2=*R1*
echo $file2
22NGS71294_S191_R1_001.fastq.gz
echo ${file2#*[_ ]}
22NGS71294_S191_R1_001.fastq.gz
I have no idea why this is not working, as the echo command of $file and $file2 gives the exact same results. Could someone please explain this behaviour?
echo $file2
, doecho "$file2"
. Then you'll see what is actually infile2
, and you'll understand why it doesn't work. – Ljm Dullaart Jan 26 '23 at 23:03echo {$file2}
gives 22NGS71294_S191_R1_001.fastq.gz toostill not sure how I can solve that problem though. I am using an array to loop through certain directories and then extracting the realpath of the files that are sitting in the directories, as well as creating new files names (and the above problem relates to that)
– ch_esr Jan 26 '23 at 23:17