Efficient way to loop through list

i have a variable that contains a list of files:

varA="/var/tmp/hello_0_myapp
/var/tmp/mello_1_myapp
/var/tmp/jello_2_myapp
/var/tmp/fello_3_myapp"

And i'm calling this variable in several functions:

col0 () {
        FILE=$(echo "${varA}" | egrep "_0_myapp" | sed "s~_0_myapp~~g")
                        eachfile=${FILE}
}

col1 () {
        FILE=$(echo "${varA}" | egrep "_1_myapp" | sed "s~_1_myapp~~g")
                        eachfile=${FILE}
}

col2 () {
        FILE=$(echo "${varA}" | egrep "_2_myapp" | sed "s~_2_myapp~~g")
                        eachfile=${FILE}
}

col3 () {
        FILE=$(echo "${varA}" | egrep "_2_myapp" | sed "s~_2_myapp~~g")
                        eachfile=${FILE}
}

As you can see here, inside each function, im going through each file in the "varA" variable which contains a very huge list of files. i'm echoing the varA variable several times.

how can this be done more efficiently?

btw, i only listed 4 functions here. but in the actual script, there are several functions. so i need this to be very efficient

Anything will be more efficient than the echo | grep | sed | awk | kitchen | sink you have now, but the basic shell for loop is intended for exactly this situation:

for X in $VAR
do
        echo "$X"
done

Do not quote $VAR, it depends on it being split on spaces or newlines.

It'd be helpful to see how you're actually using col0(), col1(), etc too.

Take a step back to where that variable is assigned. Where do the values come from? A file? The output of a "command substitution" (that could be redirected to a file as well)?
Why don't you read the values from that file in your functions?

I agree, the taken division into functions seems not optimal.
How often is each function called? A function makes most sense when it is called multiple times.
--
A technical simplification: the two commands

grep "_1_myapp" | sed "s~_1_myapp~~g"

can be done by only sed

sed -n  "s~_1_myapp~~gp"

The p modifier prints if a substitution took place.
The -n option suppresses the default print.
The g modifier only makes sense when you expect multiple _1_myapp per line.

OK, you seem to need the FILE variable to become a chopped-off filename depending on an integer 0 - 3. Given your variable contains

echo "$varA"
/var/tmp/hello_0_myapp
/var/tmp/mello_1_myapp
/var/tmp/jello_2_myapp
/var/tmp/fello_3_myapp

(whereever this might come from), you might get results very efficiently using an array (assuming bash ):

ArrA=( ${varA//_?_myapp/} )
echo ${ArrA[@]}
/var/tmp/hello /var/tmp/mello /var/tmp/jello /var/tmp/fello

and then assign FILE=${ArrA[2]} , for example, yielding

echo $FILE
/var/tmp/jello

. Would this come close to what you need? The number of "functions" would be (not quite, but almost) unlimited.

In bash or ksh93 you could use arrays, like so (keeping you col functions, but consolidating them into one:

varA="/var/tmp/hello_0_myapp
/var/tmp/mello_1_myapp
/var/tmp/jello_2_myapp
/var/tmp/fello_3_myapp"

oldIFS=$IFS
IFS=$'\n' 
arrA=( $varA )
IFS=$oldIFS

col() {
  eachfile=${arrA[$1]%%_*}
}

col 0; echo $eachfile
col 1; echo $eachfile
col 2; echo $eachfile
col 3; echo $eachfile

Output:

/var/tmp/hello
/var/tmp/mello
/var/tmp/jello
/var/tmp/fello