I have never programed in bash before.
I am reading all the files that are in a directory, then I need to look into their names and check if the have R1 or R2, depending on that I need concatenate all files that have R1 in the same and all files that have R2 in the name.
So as a final output I would like to have something like:
String 1 = file1_R1.gz file2_R1.gz file3_R1.gz…
String 2 = file1_R2.gz file2_R2.gz file3_R2.gz…
how can I do that? the only code that I have so far is:
#!/bin/bash
list=$(echo *.gz)
strR1="R1"
strR2="R2"
if [ "$list" = "*.gz" ] ; then list=""; fi
for str in $list
do
if echo "$strR1" | grep -q "$str"; then
echo "str";
else
echo "no file";
fi
done
I can read all the files in the directory but when I do the if I cannot find any file with R1, and I know that there are at least 4 files with R1 in the name.
Thank you!
Why write a loop to do the filtering wildcards will already do for you? (You’re using the same thing to filter
*.gzalready.)Since you said you want to concatenate all those files, that would then be
or something like that.