2
I need to find outdated lines in a csv file and replace them with new lines.
These are the commands that find the lines that will be replaced(old) and that will replace(new).
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 chunk 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 the diff returns only one line between the two files, replace is done quietly. But if it has two or more lines to update, it does not replace any of them.
I imagine if the variables $linhas_antigas
and $linhas_novas
were arrays to facilitate the process.
But how to do this? Is there any other solution??
Put some examples of the lines. I’ve done something similar, I await examples of lines.
– Alessandro Schneider
Ancient: Gabriel Hardoim;10;52;3 New: Gabriel Hardoim;12;55;3
– Gabriel Hardoim
The archives
.CSV
will always have the same amount rows/records ? If the corresponding row does not exist, it should be removed ? The order of records matters ?– Lacobus