In regexes, the star * is a repetition indicator for the preceding atom ( man regex ) which you do not specify when defining dddd .
You seem to grep for a structure like _nnBC . Will nn always be two digits, also below 10, e.g. 03? Then, extra care must be taken. Or do you start from the first positional parameter ( $1 )?
I delete $ ... from $1 to 1
I add the input file name (inputfile)
new version of the code...
for ((b=1; b<=96; b++)) do dddd=*"_"${b}"BC" grep -w "$dddd" inputfile > $dddd done
The variable "b" start from 1 and finisch to 96 ... no 01,02...
I take a look in the "man regex" and I found that:
$ man regex
REG_BADRPT
Invalid use of repetition operators such as using '*' as the first character.
How can I build my variable dddd?
dddd="_"${b}"BC :doesn't work... How can I replace "" with an other simbol with the same function...?
I found:
. Matches any single character
? The preceding item is optional and will be matched, at most, once
* The preceding item will be matched zero or more times.
You don't need the * . As the regex is not anchored (at begin-of-line), grep will match anywhere in the string. For the leading zeroes, try either a printf "%02d" , or for b in {01..96} (recent shells only).
Another bash-4 construct gives you two digit values
echo {01..96}
for b in {01..96}
do
...
done
Maybe you want to cycle through all the numbers in the file?
And is it sorted?
Then consider this one
while IFS=, read left right
do
if [[ $left == *[0-9][0-9]BC ]]
then
if [[ $left != $prev ]]
then
exec 3> "$left".csv
prev=$left
fi
echo "$left,$right" >&3
fi
done < inputfile.csv