I have a couple of 100 source files and 22,000 variable names to replace. Made a sed script with the replace variables, in file ReplaceScript, like this:
#! /usr/bin/sed -f
s/foo1/bar1/g
s/foo2/bar2/g
s/foo3/bar3/g
Need to replace variable names in all .c files in a tree. In the base directory to be searched, I've used the following command:
find . -type f -name "*.c" -exec sed -i '' -f ./ReplaceScript {} +
sed: 1: ./ReplaceScript: bad flag in substitute command: 's'
Single replacement command did work as intended:
find . -type f -name "*.c" -exec sed -i '' 's/foo1/bar1/g' {} +
My question: how do I fix my bad flag?
Update:
Using GNU sed results in a different error:
find . -type f -name "*.c" -exec /usr/local/bin/sed -i -f ./ReplaceScript {} +
/usr/local/bin/sed: file ./ReplaceScript line 1: unknown option to `s'
Update
It turns out to be two problems:
1. DOS carriage returns instead of unix ones.
2. little endian UTF 16 file format, must be ASCII for sed
to parse correctly.
Update 2 A duplicate? The same answer to a different question, with an extra UTF 16 problem on top?