I am trying to make my bash script a function with Bash input parameter but AWK's syntax is causing a problem. Original AWK code http://stackoverflow.com/a/19602188/54964awk -F \*,\* '{print $2}' textfile.csvPseudocode with Bash parameter $1file=$(awk -v colN=$1 -F \*,\* '{print $${colN}}' ${input}) # http://stackoverflow.com/a/19602188/54964 # http://stackoverflow.com/a/19075707/54964The problem is the part print $${colN}. Current output fails to catch the second column and takes the whole line etc-0.21,-0.245-0.205,-0.22Having only print $colN is not correct, since it takes then always the first column regardless of the value in $1. Example of the use case where I call it by bash code.bash 2; or complete script here which works if you do not hard-code which column to choose (1/2) in all two-column CSV files for the joined result of second columns#!/bin/bashids=(101 118 201)dir=/home/masi/Documents/CSV/index=0for id in ${ids[@]};do        input=$(echo ${dir}P${id}C1.csv)        # take second column of the file here        file=$(awk -v colN=$1 -F \*,\* '{print $colN}' ${input}) # http://stackoverflow.com/a/19602188/54964 # http://stackoverflow.com/a/19075707/54964        Ecgs[${index}]=${file}        index=$index+1doneInputs multicolumn 1.csv 2.csv 3.csv-0.21,-0.245-0.205,-0.22Wanted output101,118,201-0.245,-0.245,-0.245-0.22,-0.22,-0.22OS: Debian 8.5Bash 4.30   
How to expand this awk column 2 selector with Bash parameter $1?
bash;awk;csv
Using Bash and AWK in the case will be very hard. I could not solve the problem by the solutions proposed here. You are going to have much problems with /'/... so a single tool is necessary here. Use just gawk as discussed in the thread ECG Bash selection tool. # https://codereview.stackexchange.com/a/146370/122105#!/usr/bin/gawk -f# https://www.gnu.org/software/gawk/manual/html_node/Join-Function.html@include join.awkBEGIN {    FS = \*,\*;    last_row = 0;}BEGINFILE {    rows[0][ARGIND] = gensub(.*P([0-9]*)C.*, \\1, g, FILENAME);}{    rows[FNR][ARGIND] = $col;    if (FNR > last_row) { last_row = FNR; }}END {    for (r = 0; r <= last_row; r++) {        print join(rows[r], 1, ARGC - 1, ,);    }}Please, read the complete answer of 200_success here with excellent explanations. 