I have a CSV file with tuples of values where I need to change occurrences of one into another in a different (large) file.
Thus far, I have done a while read line [...] < foo.csv, essentially running sed one time for each line in the CSV file.
This takes quite some amount of time, so I wondered if I should change the while loop to construct a very long string of multiple -e statements, and then running that with eval.
I could try, obviously, but if someone can tell me if sed will just, essentially, do the same that I have done thus far, namely running through the file for each -e statement, meaning that no performance gain is to be had, then I don't think I shall bother.
Edit after comments:
Basically, I do the following:
while read line do old_user=echo $line | cut -d \; -f 2|tr -d \" new_user=echo $line | cut -d \; -f 4|tr -d \" if [ "$old_user" != "$new_user" ] then sed -i -e "s/^(.*ri:username=\")$old_user(\".*)$/\1$new_user\2/g" confluence/entities_converted.xml fi done < usernames.csv
If you notice that it's an XML file, the reason is that there are a number of instances where XML parsing and rewriting is cumbersome, hence
sed. I just wonder if, instead of running
sed multiple times, I should construct multiple
-e arguments to
usernames.csv looks like
"Full name";"Username";"Email";"New username" "Sune Mølgaard";"sune.molgaard";"firstname.lastname@example.org";"smo"
There may be any number of lines along the way of the second line, hence the looping. I am aware that the first line probably won't match, but that is insignificant.