I just played with this locally and got it to work with just a few changes. First, like @Markus mentioned in his comment, you're missing a done to terminate the for loop. I'd also move the cat result_branch.csv statement outside of the for loop so that only runs once at the end. The loop now looks like this:
for page in $(seq 1 $number_of_pages); do
curl --silent --header "Private-Token: $token" "https://gitlab.com/api/v4/groups/8523968/projects?include_subgroups=true&page=$page" | jq -r '.[] | [.id, .name, .web_url, .default_branch, .namespace.id] | @csv' >> result_branch.csv
done
cat result_branch.csv | awk {'print$4'} > branches
The next issue is due to awk's default field separator. In that last step, you're getting strange results since awk is using its default field separator instead of what you intend it to do: break on the commas. This is an easy fix with the -F flag to set the field separator:
cat result_branch.csv | awk -F, {'print$4'} > branches
All together the script becomes:
echo "Project_id, Project_Name, Project_url, Project_default_branch, Group_id" > result_branch.csv
number_of_pages=$(curl -s --head "https://gitlab.com/api/v4/groups/8523968/projects?private_token=$token" | grep -i x-total-pages | awk '{print $2}' | tr -d '\r\n')
for page in $(seq 1 $number_of_pages); do
curl --silent --header "Private-Token: $token" "https://gitlab.com/api/v4/groups/8523968/projects?include_subgroups=true&page=$page" | jq -r '.[] | [.id, .name, .web_url, .default_branch, .namespace.id] | @csv' >> result_branch.csv
done
cat result_branch.csv | awk -F, '{print $4}'
One last thing to note is that your two awk statements are written different ways: awk '{print $2}' vs. awk {'print $4'}. This doesn't seem to make a difference as in my testing I didn't adjust these and it worked just fine, but I always like to do something like this the same way every time, so I'd recommend you use one way or the other and stick with it.