Let's say I have the following csv file:
A,1
A,2
B,3
C,4
C,5
And for each unique value i in the first column of the file I want to write a script that does some processing using this value. I go about doing it this way:
CSVFILE=path/to/csv
VALUES=$(cut -d, -f1 $CSVFILE | sort | uniq)
for i in $VALUES;
do
cat >> file_${i}.sh <<-!
#!/bin/bash
#
# script that takes value I
#
echo "Processing" $i
!
done
However, this creates empty files for all values of i it is looping over, and prints the actual content of files to the console.
Is there a way to redirect the output to the files instead?

$CSVFILE=path/to/csvis an error. You likely wantedCSVFILE=path/to/csv? Also,-f4does not exist in your CSV sample, did you mean-f1? With those changes, I am gettingfile_A.sh,file_B.shandfile_C.shwith the quoted content, not empty files.cat - >> file <<-!(note the-added aftercat). Good luck to all.