In my bash script, I am trying to replace all apostrophes(') with two apostrophes('') in a csv file in order to commit it to a postgres database. As you know all single quotes in a postgres query need to be escaped with an apostrophe.
I can't use double quotations around my variables in my query because they also have double quotes in them too. So there is no easy way out apart from doing a blanket replace using sed. I have experimented with the following ways but to no avail:
sed "s/\'/\'\'/g" test.txt #Does not work
sed "s/'/''/g" test.txt #Does not work
sed s/\'/"\'\'"/g test.txt #Does not work
Does anyone have ideas on how I can get this to work?