Running grep inside a loop is a massive antipattern. Try this instead.
awk -F "," 'NR==FNR { key[$1]=$2; value[$1]=$3; next }
($1 in key) && ($0 !~ "^" $1 ",.*," key[$1] "," value[$1] ",")' input.csv modded_file.csv.dat
I have not tried to understand why you want or expect the \r in there somehow so this probably requires some tweaking.
An Awk script consists of a sequence of *condition { action } pairs, which are applied each in turn on each input line. You can use next to skip the remaining script for this input line and skip to the next input, and you can omit the { action } part if you simply want to print the entire input line. (You can also omit the condition if you want to do something unconditionally.) Each line is split into fields which are available as $1, $2, etc within the script. -F "," sets the field separator to comma (the default is a sequence of whitespace).
The NR==FNR idiom is a common way to process two input files in Awk. The overall line number NR will be equal to the line number within the file FNR when you are processing the first input file, and false subsequently.
When we are reading the first file, we store the fields in two associative arrays, both keyed by the first field.
When we are reading the second file, we print every input line where the key is found in the key array, and the entire line does not match the expected regular expression (first field is key, followed by anything, followed by a comma, the column name we stored in key[$1], another comma, the expected value we stored in value[$1], and yet another comma).
In other words, this finds the lines where the expected condition was not met. Take out the ! if you want the matches instead.
cut,echoandsed, you could replace all by a simplesed -E "s/.*,(.*),(.*)/'\1.*,\2'/", but actually you don't want the single quotes to be part of the search pattern, so it's-E "s/.*,(.*),(.*)/\1.*,\2/". Escape the pattern variable with double quotes, like @Romeo indicated in his answer.for pattern in "$(sed -E "s/.*,(.*),(.*)/\1.*,\2/" input.csv)"; do grep "$pattern" modded_file.csv.dat; doneto iterate through your input file. You can also do the whole thing in one pass, but this requires deepersedorawkexperience