I need to find outdated rows in a csv file and replace them with new rows.
These are the commands that find the lines that are going to be replaced (old) and that will replace (new) lines.
linhas_antigas=$(diff -y arquivo_com_linhas_antigas.csv arquivo_com_linhas_novas.csv | grep -e "|" | awk -F"|" '{ print $1 }')
linhas_novas=$(diff -y arquivo_com_linhas_antigas.csv arquivo_com_linhas_novas.csv | grep -e "|" | awk -F"|" '{ print $2 }' | sed 's/\t *//')
Then I run the following excerpt to replace:
while read -r arquivo_antigo
do
echo ${arquivo_antigo//"$linhas_antigas"/"$linhas_novas"}
done < arquivo_com_linhas_antigas.csv
Now the problem ... When diff returns only one line between the two files, replace is done quietly. But if you have two or more rows to update, it does not replace any of them.
I imagine that if the variables $linhas_antigas
and $linhas_novas
were arrays it would facilitate the process.
But how to do that? Do you have any other solution ??