you sould use awk to parse usernames.csv (where field 2 and 4 are different), and generate sed file.
tr -d \" username.csv |
awk -F\; '$2 != $4 { printf "s/^(.*ri:username=%c)%s(%c.*)$/\\1%s\\2/g\n",34,$2,34,$4 ; }' |
sed -i -f - confluence/entities_converted.xml
some trick
- use printf "..%c..",34 to generate quotes.
- you can skip the sed line in debug part to make sure all sed instructions are properly generated.
- do you need
/gin substitution ?
on my test file
;foo;;foo;;
;fubar;;mr X;;
;bar;;bistro;;
"Full name";"Username";"Email";"New username"
"Sune Mølgaard";"sune.molgaard";"[email protected]";"smo"
this generate
s/^(.*ri:username=")fubar(".*)$/\1mr X\2/g
s/^(.*ri:username=")bar(".*)$/\1bistro\2/g
s/^(.*ri:username=")Username(".*)$/\1New username\2/g
s/^(.*ri:username=")sune.molgaard(".*)$/\1smo\2/g
I don't bother with quotesto remove Username's line, if not found, no substitute.