This is the content of list.csv:
Apple,Red,10
Banana,Yellow,3
Coconut,White,18
Suppose I have this GNU parallel command:
parallel -a list.csv -j0 -C, \
color=`echo {2} | sed 's/e/eee/g' | ./capitalize.sh` ";" \
echo "{2}" ";" \
echo "$color" ";"
To get:
Red
REEED
Yellow
YEEELLOW
White
WHITEEE
Why isn't the color variable being defined/printed?
EDIT 20151218:
Now that I got the quoting right, I'd like to introduce a function reading a variable from another function, and reading $0.
This is a working example without GNU parallel (I made grep case-insensitive before posting, to facilitate testing without ./capitalize.sh).
while read line; do
doit() {
color=`echo $1 | cut -d, -f2 | sed 's/e/eee/g' | ./capitalize.sh`
}
export -f doit
get_key() {
key=`grep -i $color $0 | cut -d, -f2`
}
export -f get_key
#note that I would use parallel's `-C,` here instead of `cut`.
doit $line #get CSV's 2nd element and make it look like the one in script.
get_key #extract this element's value from the script's comments.
echo "color: $color"
echo "key: $key"
done < list.csv
#Key database in the shell script
# REEED,r-key
# YEEELLOW,y-key
# WHITEEE,w-key
Working output:
color: REEED
key: r-key
color: YEEELLOW
key: y-key
color: WHITEEE
key: w-key
-k/--keep-orderto buffer and reassemble output).sed).