awk -F, '{ system("mkdir -p "$2); print > $2"/"$2".csv"}' Input.csv
Assuming your Input.csv contains:
aaa,K1,ppp
ddd,M3,ppp
bbb,K1,ppp
ccc,L2,ppp
And this file is in /c/Test/
and you want directories to be created in /c/Test/
.
The main difference with your attempt is system("mkdir -p "$2)
i.e put $2
outside of quotes. This will concatenate "mkdir -p "
and the value of $2
. When you put it inside quotes it becomes literal $2
and the value is not available to mkdir
command.
After the directory is created, it prints output to the desired file which has the path $2"/"$2".csv"