Single line:
awk -F "," 'NF>1 && NR>1 {print $0 >> ("data_" $1 ".csv"); close("data_" $1 ".csv")}' data.csv
This creates new files called data_ABW , etc., containing the relevant information. Part NR>1 skips the title bar. Then for each row, she adds this whole row ( $0 ) to a file named Data_$1 , where $1 is replaced by the text in the first column of this row. Finally, the close statement ensures that there are not too many open files. If you do not have many countries, you can get rid of this and significantly increase the speed of the team.
In response to the @Lenwood comment below, to include a header in each output file, you can do this:
awk -F "," 'NR==1 {header=$0}; NF>1 && NR>1 {if(! files[$1]) {print header >> ("data_" $1 ".csv"); files[$1]=1}; print $0 >> ("data_" $1 ".csv"); close("data_" $1 ".csv")}' data.csv
(Perhaps you need to avoid the exclamation mark ...) The first new part is NR==1 {header=$0}; just saves the first line of the input file as a header variable. Then another new part if(! files[$1]) ... files[$1]=1}; uses the associative files array to track everything whether it included the header in the given file, and if not, it puts it there.
Note that this adds files, so if these files already exist, they are simply added. Therefore, if you get new data in your main file, you probably want to delete these other files before you run this command again.
(If this is not obvious, if you want the files to be named as data_Aruba , you can change $1 to $2 )
source share