Hi I am new to all of this so any help is appreciated!! I have a list of files that I want my bash script to work on such as
BG2_45TS02.assembled.fast
BG2_45TS02.riboassembled.fastq
BG3_45TS02.assembled.fastq
BG3_45TS02.riboassembled.fastq
BG4_45TS02.assembled.fastq
BG4_45TS02.riboassembled.fastq
If I only want to pick out those starting with BG2 and those ending with .riboassembled.fastq
does this work BG2*.riboassembledfastq so for example my script would be
for file in $STEP_2/BG2*.riboassembled.fastq
Yes, that will work.
You can simply try with using
echo
orprintf
in your loop:Search for
globbing
to get more information and tutorials on how it works, e.g. https://www.tldp.org/LDP/abs/html/globbingref.htmlNote, variables containing file names (here
$STEP_2
) should be put in double quotes, otherwise it will cause problems if the variable contains spaces.As pLumo suggested, you could use
$file
variable to point at your current fileRun:
Result:
Run:
Result:
Instead of
do cat $file
you could use something else.cat $file
is only for demonstration.