Im trying to make this pipeline more flexible. So say I want to be able to easily switch the number of times a for loop is run, based on whether or not I want to analyse all my data.
#!/bin/bash
#AllCohorts='Yes'
AllCohorts='NotAll'
groups=$(wc -l Groups | awk '{print $1}' )
if [[ $AllCohorts == *Yes* ]]
then
for pheno in `seq 1 $groups`;
do
out=$(sed -n "$pheno"'p' Groups)
whichPheno=$pheno
elif [[ $AllCohorts == *Not* ]]
then
nbGroups=$(wc -l TestingGroups | awk '{print$1}')
for pheno in `seq 1 $nbGroups`;
do
out=$(sed -n "$pheno"'p' Groups)
hit=$(grep -n $out TestingGroups)
whichPheno=${hit%:*}
fi
This gives an error:
$ sh run_gene_tests.sh
run_gene_tests.sh: line 29: syntax error near unexpected token `elif'
run_gene_tests.sh: line 29: `elif [[ $AllCohorts == *Not* ]]'
What Im wondering is, does the code you have in between the if and elif/fi have to be self contained? or can you do what im trying here and just have the for loop starting in one of two ways based on AllCohorts
donefrom yourforloop.donewc -l < filename. This passes the contents of the file on standard input so you don't need to then use another tool to remove the filename from the output.