I have a CSV file, with the columns like below,
User Name Env Role
user1 pap dev dev
user2 nic uat test
I need to extract a row, with respect to either the column 'Env' or 'User'. The script 'extract.sh' I have written is,
k=$2
field=$3
head -1 $1; cat $1 | awk -F "," -v k=`echo $k` -v field=`echo $field` '{ k=k;j=$field; if ( j==k ) print $0}'
The script is called with 3 parameters like this , sh extract.sh username.csv dev 3 the first parameter is csv file the second is the value and the third is column no, the output i am getting is
User Name Env Role
user1 pap dev dev
But I need the output like this,
User = user1
Name = pap
Env = dev
Role = dev
Could anyone please help me in getting this ?
-v k="$k" -v field="$field"