I am dealing with the design of bash routine which consist of several functions designed to proces step-by-step input data
The first function sorts lines in each of processed CSVs based on the numbers either in the column 2 or column3:
# function 1: sort data using either function 1 or function 2
sort_data () {
for csv in "${rescore}"/${str_name}/*.csv; do
csv_name=$(basename "$csv" .csv)
# A) sorting based on the first column :
#sort -k1.4,1n ${csv} > "${rescore}"/${str_name}/${csv_name}_std.csv
# B) sorting based on the second column (dG):
LC_ALL=C sort -k2,2g ${csv} > "${rescore}"/${str_name}/${csv_name}_std.csv
rm $csv
done
}
In this case sorting method A is disabled (comented) manually, so the script uses method B. I need to add a condition in this function that would switch beetween A and B depending on the option defined during execution of my bash script in the shell.
The same logic for the second function (in the same bash script), which merge several input CSV files and then remove repeated columns in the merged file
# function 2: fuse several files and remove repeated columns via AWK if it's nessesary
table_fuse () {
paste -d'\t' "${rescore}"/${str_name}/*.csv >> "${rescore}"/${str_name}/${dataset}_${str_name}.csv | column -t -s$'\t'
## remove repeated columns: only to activate with sorting method A
#awk '{first=$1;gsub(/[Ll]ig([0-9]+)?(\([-azA-Z]+\))?/,"");print first,$0}' "${rescore}"/${dataset}_${str_name}.csv > "${rescore}"/${dataset}_${str_name}_fin.csv
}
In this case the AWK part of the function 2 is disabled and I need to activate it or disable depending on the same option defined for the first function during execution of my bash script.
Consequently, while executing my bash script with the option --sort=1 the sorting method A should be used (uncomented) for the first function and the AWK command in the second function should be uncomented (enabled); and with --sort--2, the soring method B should be selected (in function 1) and the AWK command (in function 2) should be comented (disabled)